#include #include using namespace std; int main() { int n, m; string s, t; cin >> n >> m >> s >> t; int sa = 0, sb = 0, ta = 0, tb = 0; for (int i = 0; i < n; i++) if (s[i] == 'A') sa++; else sb++; for (int i = 0; i < m; i++) if (t[i] == 'A') ta++; else tb++; cout << min(sa, ta) + min(sb, tb) << endl; return 0; }