#include using namespace std; using ll = long long; using Graph = vector>; int main() { int N,M; cin >> N >> M; string A; cin >> A; string B; cin >> B; int ua = 0; int ub = 0; int da = 0; int db = 0; for(int i = 0; i < N; i++) { if(A[i] == 'A') { ua++; } if(A[i] == 'B') { ub++; } } for(int i = 0; i < M; i++) { if(B[i] == 'A') { da++; } if(B[i] == 'B') { db++; } } int ans = min(ua,da) + min(ub,db); cout << ans << endl; }