#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
void test_case() {
  string s, t;
  cin >> s >> t;
  long long L = 0, R = 0, n = (long long)((s).size()),
            m = (long long)((t).size());
  vector<array<long long, 2>> a(m);
  while (R < m) {
    if (s[L] == t[R]) {
      a[R][0] = L;
      R++;
    }
    L++;
  }
  L = n - 1, R = m - 1;
  while (R >= 0) {
    if (s[L] == t[R]) {
      a[R][1] = L;
      R--;
    }
    L--;
  }
  long long ans = a[0][1];
  for (long long i = 0; i < m - 1; i++) {
    ans = max(ans, a[i + 1][1] - 1 - a[i][0]);
  }
  ans = max(ans, n - 1 - a[m - 1][0]);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) {
    test_case();
  }
  return 0;
}
