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