NM=input() NM=NM.rstrip().split(" ") N=NM[0] M=NM[1] O=input() OA=O.count("A") OB=O.count("B") U=input() UA=U.count("A") UB=U.count("B") print(min(OA,UA)+min(OB,UB))