n, m = gets.split.map(&:to_i) s = gets.chomp t = gets.chomp c1 = s.count(?A) c2 = t.count(?A) p [c1, c2].min + [n - c1, m - c2].min