#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s, t;
  cin >> s >> t;
  long long n = (long long)t.size();
  vector<long long> lst(n + 1);
  long long i = n - 1;
  long long m = (long long)s.size();
  lst[n] = m;
  long long j = m - 1;
  while (i >= 0) {
    if (s[j] == t[i]) {
      lst[i] = j;
      i--;
    }
    j--;
  }
  long long ans = lst[0];
  j = 0;
  for (long long i = 0; i < n; i++) {
    while (s[j] != t[i]) j++;
    ans = max(ans, lst[i + 1] - j - 1);
    j++;
  }
  cout << ans;
  return 0;
}
