n,m=map(int,input().split()) s=input() t=input() sa=s.count("A") sb=s.count("B") ta=t.count("A") tb=t.count("B") print(min(sa,ta)+min(sb,tb))