#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  vector<int> store(t.length() + 1);
  int pos = 0;
  store[0] = -1;
  for (int i = 0; i < (int)s.size(); i++) {
    if (pos == ((int)t.length() + 1)) break;
    if (s[i] == t[pos]) {
      store[pos + 1] = i;
      pos++;
    }
  }
  pos = (int)t.length();
  int ans = (int)s.size() - 1 - store[pos];
  pos--;
  for (int i = (int)s.size() - 1; i >= 0; i--) {
    if (pos < 0) break;
    if (s[i] == t[pos]) {
      ans = max(ans, i - store[pos] - 1);
      pos--;
      continue;
    }
    if (i == store[pos]) pos--;
  }
  cout << ans;
}
