#include using namespace std; int main() { int N, M, A, B, C, D; string S, T; cin >> N >> M >> S >> T; A = count(S.begin(), S.end(), 'A'); B = count(T.begin(), T.end(), 'A'); C = count(S.begin(), S.end(), 'B'); D = count(T.begin(), T.end(), 'B'); cout << min(A, B) + min(C, D) << "\n"; }