#include <iostream>
#include <unordered_map>
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

int main() {
    string T, S;

    cin >> T;
    cin >> S;

    vector<char> redosled;
    unordered_map<char, int> hmap;

    vector<char> queue;

    for (char c : S) {
        redosled.push_back(c);
    }

    int TOTAL_COUNT = 0;

    int i_r = 0;
    int i_q = 0;

    for(int i=0;i<T.length();i++) {
        if(T[i] == redosled[0]) {
            string new_str = T.substr(++i, T.length());
            
            queue.push_back(redosled[0]);
            i_r++;

            hmap[redosled[0]] = 1;

            for (char c : new_str) {
                if(c == queue[i_q]) {
                    hmap[queue[i_q]] += 1;

                } else if(c == redosled[i_r]) {
                    hmap[c] = 1;
                    queue.push_back(c);
                    i_r++;
                }

            }

            if(redosled.size() == queue.size()) {
                int min = INT_MAX;
                
                for (auto item : hmap) {
                    if(min > item.second)
                        min = item.second;
                }

                TOTAL_COUNT += min;
            }
        }


        i_q=0;
        i_r=0;
        queue.clear();
        hmap.clear();
    }
    
    cout << TOTAL_COUNT;
}