n, m = map(int, input().split()) s = input() t = input() sa = s.count("A") ta = t.count("A") print(min(sa, ta) + min(n - sa, m - ta))