def min(a, b): return a if a <= b else b input_list = list(map(int,input().split())) n, m = input_list s = input() t = input() mudi = min(s.count('A'), t.count('A')) gara = min(s.count('B'), t.count('B')) res = mudi + gara print(res)