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