Electrons in the highest energy level are called valence electrons. Valence electrons are really important because they help to determine chemical properties like the reactivity of an element. Let's figure out the number of valence electrons for the element magnesium.
Mg has two valence electrons.
The electron configuration for magnesium is shown below.
The valence elctrons are the electrons in the third energy level (3s sublevel has two electrons in an atom of Mg)
Here is a video which discusses how to determine the electron configuration of magnesium.