m, n = map(int,input().split()) s = input() t = input() ans = min(s.count("A"),t.count("A"))+ min(s.count("B"), t.count("B")) print(ans)