import sys input = sys.stdin.readline from collections import Counter N,M=map(int,input().split()) S=input().strip() T=input().strip() A=Counter(S) B=Counter(T) ANS=min(A["A"],B["A"])+min(A["B"],B["B"]) print(ANS)