#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1000000007;
const long long INF = 1e18;
const int MX = 2000000001;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long tw, q, n, a, b, gk, l, ma, r, x = 0, y = 0, ans = 0, temp = 0,
                                          res = 0;
  string second, t, rv;
  cin >> second >> t;
  rv = t;
  reverse(rv.begin(), rv.end());
  int slen = second.size();
  int tlen = t.size();
  vector<int> pref(tlen), suf(tlen);
  int k = 0;
  for (int i = 0; i < slen; i++) {
    if (second[i] == t[k]) {
      pref[k] = i;
      k++;
    }
    if (k == tlen) break;
  }
  k = tlen - 1;
  for (int i = slen - 1; i >= 0; i--) {
    if (second[i] == t[k]) {
      suf[k] = i;
      k--;
    }
    if (k < 0) break;
  }
  int mx = max(suf[0], slen - 1 - pref[tlen - 1]);
  for (int i = 0; i < tlen - 1; i++) {
    mx = max(mx, suf[i + 1] - pref[i] - 1);
  }
  cout << mx << "\n";
}
