#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
const int INF = (int)1e9 + 1;
const long double EPS = 1e-9;
const int maxn = (int)1e3 + 10;
char s[maxn];
const int maxm = (int)1e6 + 10;
char t[maxm];
bool solve() {
  if (scanf("%s%s", s, t) < 2) {
    return 0;
  }
  int n = (int)strlen(s), m = (int)strlen(t);
  int ansl = 0, ansr = m;
  for (int rev = 0; rev < 2; ++rev) {
    int pos = 0, i;
    for (i = 0; pos < n && i < m; ++i) {
      if (s[pos] == t[i]) {
        ++pos;
      }
    }
    if (pos < n) {
      printf("0\n");
      return 1;
    }
    int l, r;
    if (!rev) {
      l = i, r = m;
    } else {
      l = 0, r = m - i;
    }
    ansl = max(ansl, l);
    ansr = min(ansr, r);
    reverse(s, s + n);
    reverse(t, t + m);
  }
  printf("%d\n", max(0, ansr - ansl + 1));
  return 1;
}
int main() {
  srand(rdtsc());
  while (1) {
    if (!solve()) {
      break;
    }
  }
  return 0;
}
