N,M = map(int,input().split())
S = input()
T = input()
sa = S.count('A')
sb = N - sa
ta = T.count('A')
tb = M - ta
print(min(sa,ta) + min(sb,tb))