import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int sa = 0; int sb = 0; for (char c : sc.next().toCharArray()) { if (c == 'A') { sa++; } else { sb++; } } int ta = 0; int tb = 0; for (char c : sc.next().toCharArray()) { if (c == 'A') { ta++; } else { tb++; } } System.out.println(Math.min(sa, ta) + Math.min(sb, tb)); } }