how do electrons behave when metals react with non-metals