n, m = map(int, input().split()) s = list(input()) t = list(input()) s_a = s.count('A') s_b = s.count('B') t_a = t.count('A') t_b = t.count('B') print(min(s_a, t_a) + min(s_b, t_b))