Electrons present in the outermost shell of the atom of an element are called valence electrons.
3Li is an s-block element and its electronic configuration is 1s22s1. Since it has one valence electron, it is placed in group 1.
Therefore, for s-block elements, group number = number of valence electrons.
However, for p-block elements, group number = 18 – number of electrons required to attain complete octet.
7N is a p-block element and its electronic configuration is 1s22s22p3. Since it has five electrons in its valence shell, it is short of three electrons to complete its octet.
Therefore, its group number = 18 – 3 = 15.