def min(a,b); a < b ? a : b; end N,M = gets.split.map(&:to_i) T = gets.chomp B = gets.chomp puts min(T.count('A'), B.count('A')) + min(T.count('B'), B.count('B'))