import java.io.*; import java.util.*; public class Main_yukicoder717 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int m = sc.nextInt(); char[] s = sc.next().toCharArray(); char[] t = sc.next().toCharArray(); int cnts = 0; for (char c : s) { if (c == 'A') { cnts++; } } int cntt = 0; for (char c : t) { if (c == 'A') { cntt++; } } pr.println(Math.min(cnts, cntt) + Math.min(n - cnts, m - cntt)); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes())); pr = new Printer(System.out); solve(); // pr.close(); pr.flush(); // sc.close(); } static String INPUT = null; private static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }