J.R. S. answered 05/25/22
Ph.D. University Professor with 10+ years Tutoring Experience
If you know the charge of the cation (the first element), then the anion (second element) must have a charge sufficient to balance that of the first. In the case of LiF, we know that Li is 1+ so F must be -1. If you had MgS, we know Mg is 2+ so the S must be 2-.
As for finding the electron configuration, that is simply established by looking in the periodic table and finding the configuration of the neutral atom, and then adjusting for the formation of the bond. In the case of LiF, the normal electron configuration for F is 1s2 2s2 2p5. Since the F has a 1- in LiF, it now becomes 1s2 2s2 2p6, because it has gained an electron from the Li in the formation of the ionic bond.