n,m = map(int,raw_input().split()) s = list(raw_input()) t = list(raw_input()) print min(s.count("A"),t.count("A")) + min(s.count("B"), t.count("B"))