#include <bits/stdc++.h>
using namespace std;
int main() {
  char name[1001], str[1000001];
  int posFirst = -1, pos, len, len1;
  cin >> name >> str;
  pos = -1;
  len = strlen(name);
  len1 = strlen(str);
  for (int i = 0; i < len; ++i) {
    do {
      ++pos;
    } while (str[pos] != name[i] && pos < len1);
    if (pos >= len1) {
      cout << 0;
      return 0;
    }
  }
  posFirst = pos;
  pos = len1;
  for (int i = len - 1; i > -1; --i) {
    do {
      --pos;
    } while (str[pos] != name[i] && pos > posFirst);
    if (pos <= posFirst) {
      cout << 0;
      return 0;
    }
  }
  cout << pos - posFirst;
  return 0;
}
