#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, nm;
  cin >> s >> nm;
  int l = s.length();
  int l1 = nm.length();
  int i, j, k = 0, k1;
  for (i = 0; i < l1; i++) {
    if (nm[i] == s[k]) {
      k++;
      if (k == l) break;
    }
  }
  if (i == l1) {
    printf("0\n");
    return 0;
  }
  string nm1 = nm.substr(i + 1, l1);
  int x, l2 = nm1.length();
  k = l - 1;
  for (x = l2 - 1; x >= 0; x--) {
    if (nm1[x] == s[k]) {
      k--;
      if (k < 0) break;
    }
  }
  if (x < 0) {
    printf("0\n");
    return 0;
  }
  cout << x + 1 << endl;
  return 0;
}
