#include <bits/stdc++.h>
using namespace std;
char S[1010];
char T[1000010];
int cnt;
int happy, res;
int sind, lind;
int main() {
  int i, j;
  scanf("%s", S);
  scanf("%s", T);
  int lenS = strlen(S);
  int lenT = strlen(T);
  for (i = 0; i < lenT; i++) {
    if (S[cnt] == T[i]) cnt++;
    if (cnt == lenS) break;
    sind += 1;
  }
  lind = lenT - 1;
  cnt = lenS - 1;
  for (j = lenT - 1; j > sind; j--) {
    if (S[cnt] == T[j]) cnt -= 1;
    if (cnt < 0) break;
    lind -= 1;
  }
  res = lind - sind;
  if (res > 0)
    printf("%d\n", res);
  else
    printf("0\n");
  return 0;
}
