#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define Would #define you const int INF = 999999999; const int MOD = 1e9 + 7; const double pi = 3.141592653589793238; int main() { int a, b, ans = 0; string s, h; cin >> a >> b >> s >> h; sort(s.begin(), s.end()), sort(h.begin(), h.end()); cout << min(s.find('A' - '0'), s.find('B' - '0')) + min(h.find('A' - '0'), h.find('B' - '0')) << endl; }