#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; string s, t; cin >> s >> t; int a = 0, b = 0; int x = 0, y = 0; for(int i = 0; i < n; i++) { if(s[i] == 'A') a++; else b++; } for(int i = 0; i < m; i++) { if(t[i] == 'A') x++; else y++; } cout << min(a, x) + min(b, y) << endl; return 0; }