#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  int n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  int A0 = count(s.begin(), s.end(), 'A');
  int B0 = count(s.begin(), s.end(), 'B');
  int A1 = count(t.begin(), t.end(), 'A');
  int B1 = count(t.begin(), t.end(), 'B');
  cout << min(A0, A1) + min(B0, B1) << endl;
}