Valency is the no of electrons that an atom can gain or lose during a chemical reaction.......
nitrogen has 5 (more than 4)electrons in its outer most shell or orbit
so it is deficit of 3 electrons which it can accept from other element during chemical reaction. when an atom accept electrons it gets negatively charged so the valency of nitrogen is -3 as
but boron has 3 electrons (less than 4 ) so it will readily lose electrons and become positively charge
and the valency will be +3