n, m = map(int, input().split()) s = list(input()) t = list(input()) top_a = 0 top_b = 0 botom_a = 0 botom_b = 0 for i in s: if i == "A": top_a += 1 elif i == "B": top_b += 1 for i in t: if i == "A": botom_a += 1 elif i == "B": botom_b += 1 if top_a > botom_a: a = botom_a else: a = top_a if top_b > botom_b: b = botom_b else: b = top_b print(a + b)