N, M = gets.split.map &:to_i S, T = $<.map &:chomp p [S.count(?A), T.count(?A)].min + [S.count(?B), T.count(?B)].min