#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
string s, t;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s >> t, n = s.size(), m = t.size();
  for (i = j = 0; i < m; i++)
    if (t[i] == s[j])
      if (++j == n) break;
  for (k = m - 1, j = n - 1; k >= 0; k--)
    if (t[k] == s[j])
      if (--j < 0) break;
  cout << max(0, k - i) << endl;
  return 0;
}
