// yukicoder: No.717 ファッションへのこだわり // 2019.5.2 bal4u #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() // 整数の入力(負数に対応) { int n = 0, c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } int main() { int N, M, A, B, a, b; A = B = a = b = 0; N = in(), M = in(); while (N--) if (gc() == 'A') A++; else B++; gc(); while (M--) if (gc() == 'A') a++; else b++; if (A > a) A = a; if (B > b) B = b; printf("%d\n", A+B); return 0; }