#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long f[N], l[N];
signed main() {
  string s, t;
  cin >> s >> t;
  long long n = s.length();
  long long m = t.length();
  long long idx = 0;
  for (long long i = 0; i < n; i++) {
    if (idx < m && s[i] == t[idx]) {
      f[idx] = i;
      idx++;
    }
  }
  idx = m - 1;
  for (long long i = n - 1; i >= 0; i--) {
    if (idx >= 0 && s[i] == t[idx]) {
      l[idx] = i;
      idx--;
    }
  }
  long long ans = l[0];
  ans = max(ans, n - 1 - f[m - 1]);
  for (long long i = 1; i < m; i++) {
    long long cur = l[i] - f[i - 1] - 1;
    ans = max(ans, cur);
  }
  cout << ans;
}
