#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long mod = 123457;
const long long N = 106 * 106;
const long long nax = 1e6 + 6;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  long long n = s.size();
  long long suff[n + 1], mx[t.size() + 1];
  long long now = t.size();
  for (long long i = 0; i <= t.size(); i++) mx[i] = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (now > 0 && s[i] == t[now - 1]) {
      now--;
    }
    suff[i] = now;
  }
  for (long long i = n - 1; i >= 0; i--) {
    mx[suff[i]] = max(mx[suff[i]], i);
  }
  now = -1;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (!suff[i]) ans = max(ans, i);
  }
  for (long long i = 0; i < n; i++) {
    bool b = false;
    if (now < t.size() - 1 && t[now + 1] == s[i]) now++, b = true;
    if (now < t.size() - 1 && b) {
      ans = max(ans, mx[now + 1] - i - 1);
    }
    if (now == t.size() - 1 && b) {
      ans = max(ans, n - 1 - i);
    }
  }
  cout << ans << '\n';
  return 0;
}
