#include <bits/stdc++.h>
class nullstream {
 public:
  template <typename T>
  nullstream& operator<<(T a) {
    return (*this);
  }
  template <typename T>
  nullstream& operator>>(T a) {
    return (*this);
  }
};
using namespace std;
const int K = 18;
const long long MAXN = 1e6;
const int INF = 2e9 + 1;
const long long LONG_INF = 8e18;
const long long MOD = 1e9 + 7;
const double e = 1e-9;
const long long C = 500;
const long long dx[4] = {-1, 0, 1, 0};
const long long dy[4] = {0, 1, 0, -1};
string name;
string s;
int main() {
  cin >> name >> s;
  int left_pos = 0;
  int pos = 0;
  for (; left_pos < (int)s.size() && pos < (int)name.size(); left_pos++)
    if (s[left_pos] == name[pos]) pos++;
  int right_pos = s.size() - 1;
  pos = name.size() - 1;
  for (; right_pos >= 0 && pos >= 0; right_pos--)
    if (s[right_pos] == name[pos]) pos--;
  if (left_pos > right_pos + 1)
    cout << "0\n";
  else
    cout << right_pos - left_pos + 2 << '\n';
  return 0;
}
