#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long md = 1e9 + 7;
string s, t;
long long i, j, ans, pref[200501], suff[200501], mn[200501], mx[200501], n;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s;
  cin >> t;
  s = "#" + s + "#";
  n = s.size() - 2;
  for (i = 0; i <= t.size(); i++) mn[i] = 9000000000000000000LL;
  mn[0] = 0;
  mx[0] = s.size() - 1;
  for (i = 1; i <= n; i++) {
    if (s[i] == t[pref[i]]) pref[i]++;
    pref[i + 1] = pref[i];
    mn[pref[i]] = min(mn[pref[i]], i);
  }
  for (i = n; i >= 1; i--) {
    if (s[i] == t[t.size() - suff[i] - 1]) suff[i]++;
    suff[i - 1] = suff[i];
    mx[suff[i]] = max(mx[suff[i]], i);
  }
  for (i = 0; i <= t.size(); i++) {
    ans = max(ans, mx[t.size() - i] - mn[i] - 1);
  }
  cout << ans << '\n';
  return 0;
}
