n,m = gets.chomp.split(" ").map(&:to_i) s,t = 2.times.map{gets.chomp.count("A")} puts [s,t].min+[n-s,m-t].min