An elements position on the periodic table can be used to determine how reactive it is.
In order to become stable, elements attempt to gain electrons until they contain 8 electrons in their outer most energy level. H, He, B, and Be (sometimes) only require 2 electrons in their outer most energy level in order to become stable.
In order to determine how many electrons an element has in its outer most energy level, look at the column of the periodic table it is found in. Elements in the IA column have 1 valence electron. From left to right, each successive element in the next column has one more valence electron. Elements in the O column have 8 valence electrons (save for He which has 2).
Elements combine in ways that equal a total of 8 valence electrons.
Li with 1 valence electron readily reacts with F, which has 7 electrons.
O (6 valence electrons) readily reacts with Be (2 valence electrons) in order to combine into a compound containing 8 valence electrons.
This image depicts chemical symbols surrounded by the number of valence electrons atoms of that element possess.