#include <iostream>
#include <cstdio>

#include <algorithm>
#include <cmath>
#include <cstring>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define pb(x) push_back(x)
#define mp(a, b) make_pair (a, b)
#define sqr(x) ((x)*(x))

char s[200];
char t[300000];

int cnt;
string STR[200];

char z[300000];
int x[300000];

vector <int> position[200];

void fz (int p) {
	while (z[x[p]] == z[p + x[p]]) 
		x[p]++;
}

int search (int x, int k) {
	int l = -1, r = (int) position[k].size () - 1;
	while (r - l > 1) {
		int lr = (l + r) >> 1;
		if (position[k][lr] >= x)
			r = lr; else l = lr;
	}

	if (r < 0) return -1;
	return position[k][r] >= x ? position[k][r] : -1;
}

int search2 (int x, int k) {
	int l = 0, r = (int) position[k].size ();
	while (r - l > 1) {
		int lr = (l + r) >> 1;
		if (position[k][lr] <= x)
			l = lr; else r = lr;
	}

	if (l < 0) return -1;
	return position[k][l] >= x ? position[k][l] : -1;
}

int main () {
	//freopen ("input.txt", "r", stdin);	
	//freopen ("output.txt", "w", stdout);

	gets (s); int ss = (int) strlen (s);
	gets (t); int n = (int) strlen (t), nn = n;

	for (int i = 0; i < n - 1; i++) t[i + n] = t[i];
	n += n - 1;
	
	for (int i = 0; s[i]; i++) 
		if (s[i] == '*') {
			if (STR[cnt] != "") cnt++;
		} else STR[cnt] += s[i];

	if (STR[cnt] == "") cnt--;

	if (cnt < 0) {
		printf ("%d", nn); return 0;
	}

	for (int _ = 0; _ <= cnt; _++) {
		int m = 0;
		for (int i = 0; i < (int) STR[_].size (); i++) z[m++] = STR[_][i];
		for (int i = 0; i < n; i++) z[m++] = t[i];

		int l = -1, r = -1;
		for (int i = 1; i < m; i++) {
			if (i <= r) x[i] = min (x[i - l], r - i + 1); else x[i] = 0;

			fz (i);

			if (r < i + x[i] - 1) 
				r = i + x[i] - 1, 
				l = i;			
		}

		int s_size = (int) STR[_].size ();
		for (int i = s_size; i < m; i++) 
			if (x[i] >= s_size) position[_].pb (i - s_size);
	}

	int ans = 0;
	for (int p = 0; p < nn; p++) {		
		int pos = search (p, 0);
		
		if (pos == -1 || (s[0] != '*' && pos > p)) continue;

		bool f = true;
		for (int i = 1; i < cnt; i++) {
			pos = search (pos + (int) STR[i - 1].size (), i);
			if (pos == -1) { f = false; break; }
		}
		
		if (f == false ) continue;

		if (cnt > 0) pos = search (pos + (int) STR[cnt-1].size (), cnt);
		if (pos == -1) continue;		

		pos += (int) STR[cnt].size ();
		if (pos - p > nn) continue;

		if (s[ss-1] != '*') {
			pos = search2 (p + nn - (int) STR[cnt].size (), cnt);
			if (pos == -1) continue;

			pos += (int) STR[cnt].size ();
		}

		if (s[ss-1] != '*' && pos - p != nn) continue;

		ans++;
	}

	printf ("%d", ans);
			
	return 0;
}