#include <bits/stdc++.h>
using namespace std;
string second;
char ss[2000 * 2000], t[2000];
int n, j, l, r, ok[2000];
int main() {
  scanf("%s\n", t);
  scanf("%s\n", ss);
  second = ss;
  n = second.size();
  for (int i = 0; i < strlen(t); i++) {
    while (n > j && second[j] != t[i]) j++;
    if (second[j] != t[i]) {
      printf("0\n");
      return 0;
    }
    j++;
  }
  l = j - 1;
  reverse(t, t + strlen(t));
  reverse(second.begin(), second.end());
  j = 0;
  for (int i = 0; i < strlen(t); i++) {
    while (n > j && second[j] != t[i]) j++;
    if (second[j] != t[i]) {
      printf("0\n");
      return 0;
    }
    j++;
  }
  r = n - j;
  if (r < l) r = l;
  printf("%d", r - l);
  return 0;
}
