#include <bits/stdc++.h>
using namespace std;
long long last[500005], first[500005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string second, t;
  cin >> second >> t;
  long long n = second.size();
  long long m = t.size();
  long long j = 0, i = 0;
  while (i < n && j < m) {
    if (second[i] == t[j]) {
      first[j] = i;
      ++j;
    }
    ++i;
  }
  j = m - 1;
  i = n - 1;
  while (i >= 0 && j >= 0) {
    if (second[i] == t[j]) {
      last[j] = i;
      --j;
    }
    --i;
  }
  long long ans = last[0];
  ans = max(ans, n - 1 - first[m - 1]);
  for (long long i = 1; i < m; ++i) ans = max(ans, last[i] - first[i - 1] - 1);
  cout << ans;
  return 0;
}
