#include using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; string s, t; cin >> s >> t; int scnta = 0; int scntb = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'A') scnta++; else scntb++; } int tcnta = 0; int tcntb = 0; for (int i = 0; i < m; ++i) { if (t[i] == 'A') tcnta++; else tcntb++; } int ans = min(scnta, tcnta) + min(scntb, tcntb); cout << ans << endl; return 0; }