#include <bits/stdc++.h>
using namespace std;

void transform(string& S, vector<pair<char, int>>& V) {
	char l = 0;
	int i = -1;
	for (const char& c : S) {
		if (c != l) {
			V.push_back({c, 1});
			i++;
			l = c;
		}
		else {
			V[i].second++;
		}
	}
}

int main(int argc, char const *argv[])
{
	string T, S;
	cin >> T >> S;

	if (T.length() < S.length()) {
		cout << 0 << endl;
		cout << T << endl;
		return 0;
	}

	vector<pair<char, int>> TV;
	vector<pair<char, int>> SV;

	transform(T, TV);
	transform(S, SV);

	int tmsiz = TV.size() - SV.size() + 1;
	int siz = SV.size();
	int ans = 0;
	for (int i = 0; i < tmsiz; i++) {
		int tren = numeric_limits<int>::max();
		int trenindex = 0;
		for (int j = 0; j < siz; j++) {
			//cout << i << " " << j << "  " << TV[i + j].first << " " << TV[i + j].second << "   " << SV[j].first << " " << SV[j].second << endl;
			if (TV[i + j].first == SV[j].first) {
				int val = max(0, TV[i + j].second - SV[j].second + 1);
				if (val < tren) {
					tren = val;
					trenindex = i + j;
				}
			}
			else {
				tren = 0;
				break;
			}
		}
		// /cout << endl;
		ans += tren;
		TV[trenindex].second -= tren;
	}
	cout << ans << endl;

	//for (const auto& a : TV) {
	//	cout << a.first << " " << a.second << endl;
	//}
	//cout << endl;
	//for (const auto& a : SV) {
	//	cout << a.first << " " << a.second << endl;
	//}
	return 0;
}