#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string p;
  string s;
  cin >> p;
  cin >> s;
  int l = 0;
  int r = s.size() - 1;
  for (int i = 0; i < p.size(); ++i) {
    while (l < s.size() && p[i] != s[l]) ++l;
    if (l < s.size())
      ++l;
    else {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = p.size() - 1; i >= 0; --i) {
    while (r >= 0 && p[i] != s[r]) --r;
    if (r >= 0)
      --r;
    else {
      cout << 0 << endl;
    }
  }
  ++r;
  --l;
  cout << max(0, r - l) << endl;
  return 0;
}
