#include using namespace std; typedef long long ll; int main() { int n, m; cin>>n>>m; string s, t; cin>>s>>t; int sa, sb, ta, tb; sa=sb=ta=tb=0; for (char c:s) { if (c=='A') sa++; else sb++; } for (char c:t) { if (c=='A') ta++; else tb++; } cout << min(sa, ta) + min(sb, tb) << endl; return 0; }