That's the oxidation numbers for both elements. If you look at magnesium on the Periodic table, You will see that Magnesium is in the 2nd column which means it has a +2 charge which means it wants to lose 2 electrons. Chlorine on the other hand needs to gain one electron because its right next to the Noble gases (which have an octet).
Google Oxidation numbers if this don't make sense.