import sys input = sys.stdin.readline from collections import * N, M = map(int, input().split()) S = input()[:-1] T = input()[:-1] c1 = Counter(S) c2 = Counter(T) print(min(c1['A'], c2['A'])+min(c1['B'], c2['B']))