from collections import Counter n,m=map(int,input().split()) s,t=Counter(input()),Counter(input()) print(min(s['A'],t['A'])+min(s['B'],t['B']))