#include <bits/stdc++.h>
using namespace std;
void reverseStr(string& str) {
  int n = str.length();
  for (int i = 0; i < n / 2; i++) swap(str[i], str[n - i - 1]);
}
int main() {
  string a, b, c;
  cin >> a >> b;
  int t = 0;
  int indexi = -1;
  for (int x = 0; x < b.size(); x++) {
    if (b[x] == a[t]) {
      t++;
    }
    if (t >= a.size()) {
      indexi = x;
      break;
    }
  }
  reverseStr(b);
  reverseStr(a);
  int indext = -1;
  t = 0;
  for (int x = 0; x < b.size(); x++) {
    if (b[x] == a[t]) {
      t++;
    }
    if (t >= a.size()) {
      indext = x;
      break;
    }
  }
  if (indexi == -1 || indext == -1) {
    cout << 0 << endl;
    return 0;
  }
  int x = b.size();
  int f = a.size();
  if ((x - indext + f - 2) == indexi)
    cout << 0 << endl;
  else
    cout << b.size() - indext - indexi - 1 << endl;
}
