n, m = map(int, input().split()) s = input() t = input() ans = 0 for ab in "AB": ans += min(s.count(ab) + t.count(ab)) print(ans)