#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
string l[1000000];
ll brojac=0;
string y;
void printPowerSet(string p, int set_size){

    unsigned int pow_set_size = pow(2, set_size);
    int counter, j;

    for(counter = 0; counter < pow_set_size; counter++){
        for(j = 0; j < set_size; j++){
            if(counter & (1 << j))
                if(l[counter].length()<y.length()){
                    l[counter]+=p[j];
                    brojac++;
                }
                else
                    break;
            }
    }
}


/*Driver code*/
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string p;
    int br=0;
    cin>>p;
    cin>>y;
    int u=y.length();
   /* printPowerSet(p, p.length());
    for(int i=0;i<brojac;i++)
        if(l[i]==y)
            br++;
    cout<<br;*/
    map<char,ll> mapica;
    int provera=1;
    for(int i=1;i<y.length();i++)
        if(y[i-1]!=y[i])
            provera=0;
    if(provera){
        for(int i=0;i<p.length();i++)
            if(p[i]==y[0])
                br++;
        cout<<br+1-u;

    }
    else{
        for(int i=0;i<p.length();i++)
            mapica[p[i]]++;
        ll najmanji=100000;
        for(int i=0;i<y.length();i++)
            najmanji=min(najmanji,mapica[y[i]]);
        cout<<najmanji;
    }


    return 0;
}