#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  while (T--) {
    string s, r;
    cin >> s >> r;
    int ls = 0, rs = r.size();
    for (int i = 0; ls < r.size(); ls++) {
      if (r[ls] == s[i]) {
        i++;
        if (i == s.size()) {
          break;
        }
      }
    }
    for (int i = s.size() - 1; rs >= 0; rs--) {
      if (r[rs] == s[i]) {
        i--;
        if (i == -1) {
          break;
        }
      }
    }
    if (ls <= rs) {
      cout << (rs - ls) << "\n";
    } else {
      cout << "0\n";
    }
  }
}
