from collections import * N, M = map(int, input().split()) CS = Counter(input()) CT = Counter(input()) print(min(CS["A"], CT["A"]) + min(CS["B"], CT["B"]))