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