#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string required_words, collected_words;
getline(cin, required_words);
getline(cin, collected_words);
// 使用哈希表來計算每個單字出現的次數
unordered_map<string, int> required_count, collected_count;
stringstream ss_required(required_words);
string word;
while (ss_required >> word) {
required_count[word]++;
}
stringstream ss_collected(collected_words);
while (ss_collected >> word) {
collected_count[word]++;
}
// 檢查是否可以兌換公仔
int max_exchange = INT_MAX;
for (auto& kv : required_count) {
string word = kv.first;
int required = kv.second;
int collected = collected_count[word];
if (collected == 0) {
max_exchange = 0;
break;
}
max_exchange = min(max_exchange, collected / required);
}
cout << max_exchange << '\n';
}