#include <iostream>
#include <cstdio>
#include <sstream>
#include <vector>
#include <cassert>

using namespace std;

typedef vector<int> vi;

bool eq(const string& s, size_t off, const string& p) {
	for (size_t i = 0; i < p.length(); ++i)
		if (off + i >= s.length() || s[off+i] != p[i])
			return false;
	return true;
}

void solve() {
	string p, s;
	cin >> p;
	cin >> s;	
	assert(s.length());
	s = s + s;

	string tmp = p;
	for (size_t i = 0; i < tmp.length(); ++i) if (tmp[i] == '*') tmp[i] = ' ';
	vector<string> parts;
	stringstream strin(tmp);
	while (strin >> tmp)
		parts.push_back(tmp);

	vector<vi> nxt(parts.size());
	for (size_t ti = 0; ti < parts.size(); ++ti) {
		nxt[ti].resize(s.length() + 1, -1);
		for (size_t off = 0; off + parts[ti].length() <= s.length(); ++off)
			nxt[ti][off] = eq(s, off, parts[ti]) ? off : -1;
		for (int i = s.length() - 1; i >= 0; --i)
			if (nxt[ti][i] == -1)
				nxt[ti][i] = nxt[ti][i+1];
	}

	int res = 0;
	for (size_t off = 0; off < s.length() / 2; ++off) {
		int start = (int)off;
		int pi = 0;
		
		if (p[0] != '*') {
			if (nxt[pi][start] == start) {
				start += parts[pi].length();
				++pi;
			}
			else
				continue; // bad shift
		}
		
		if (pi == parts.size()) {
			if (start == off + s.length() / 2 || p[p.length() - 1] == '*')
				++res;
			continue;
		}
		
		bool bad = false;
		
		while (pi + 1 < parts.size()) {
			int next = nxt[pi][start];
			if (next < 0) {
				bad = true;
				break;
			}			
			
			start = next + parts[pi].length();
			++pi;
			
			if (start > off + s.length() / 2) {
				bad = true;
				break;
			}
		}
		
		if (bad) continue;

		if (p[p.length() - 1] == '*') {
			int next = nxt[pi][start];
			if (next >= 0 && next + parts[pi].length() <= off + s.length() / 2)
				++res;
		} else {
			size_t pos = off + s.length() / 2 - parts[pi].length();
			if (start <= pos && nxt[pi][pos] == pos)
				++res;
		}
	}
	
	cout << res << endl;
}

int main() {
	solve();
	
	return 0;
}
