n,m =map(int,input().split()) nu =input().count("A") nd =input().count("A") print(min([nu,nd])+min([n-nu,m-nd]))