n,m=map(int,input().split()) s=input();t=input() print(min(s.count('A'),t.count('A'))+min(s.count('B'),t.count('B')))