Metallicity measurements using atomic lines in M and K dwarf stars