Valence electrons are those that are in the highest principal energy level. This is the 2nd principal energy level for O, so all the 2nd principal energy level electrons are the valence electrons, namely the 2s2 and 2p4 electrons for a total of 6 valence electrons.