#include using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) #define all(x) x.begin(),x.end() int N,M; string s,t; int main(){ cin >> N >> M; cin >> s >> t; int a = min(count(all(s),'A'),count(all(t),'A')); int b = min(count(all(s),'B'),count(all(t),'B')); cout << a + b << endl; }