#include <bits/stdc++.h>
using namespace std;
int solution(int n, int m, string s, string c) {
map<char, int> ps, pc;
for (auto it : s)
ps[it]++;
for (auto it : c)
pc[it]++;
int cnt = 0;
for (auto [k, v] : pc)
cnt += min(ps[k], v);
return cnt;
}
int main() {
cout << (solution(3, 4, "abc", "abcd") == 3) << endl;
cout << (solution(4, 2, "abbc", "bb") == 2) << endl;
cout << (solution(5, 4, "bcdea", "abcd") == 4) << endl;
return 0;
}