#include <bits/stdc++.h>
using namespace std;
int main() {
  int l = 0, r = 0;
  string s, t;
  cin >> s >> t;
  int i = 0;
  for (int j = 0; j < t.length(); j++) {
    if (s[i] == t[j]) {
      if (i == s.length() - 1) {
        i = s.length() - 1;
        l = j + 1;
        break;
      } else
        i++;
    }
  }
  for (int j = t.length() - 1; j > l - 1; j--) {
    if (s[i] == t[j]) {
      if (i == 0) {
        i = 0;
        r = t.length() - j;
        break;
      } else
        i--;
    }
  }
  if (l == 0 || r == 0) {
    cout << 0;
    return 0;
  }
  int ans;
  ans = t.length() - l - r + 1;
  cout << ans;
  return 0;
}
