#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	unordered_map<char,ll>x,y;
	for(auto c:s){
		x[c]++;
	}
	for(auto c:t){
		y[c]++;
	}
	ll ans=1e9;
	for(auto a:y)
	{
		if(x.find(a.first)==x.end()) {
			ans=0;
			break;
		}
		ans=min(ans,x[a.first]/a.second);
		
	}
	cout<<ans<<endl;
	return 0;
}