# -*- coding: utf-8 -*- from collections import Counter N, M = map(int, input().split()) S = Counter(input()) T = Counter(input()) print(min(S["A"], T["A"]) + min(S["B"], T["B"]))