n, m = map(int, input().split()) s = input() t = input() ans = sum([min(s.count(a), t.count(a)) for a in ["A", "B"]]) print(ans)