#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using i3 = pair<int, ii>;
using li = pair<ll, int>;
using lii = pair<ll, ii>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using vpll = vector<pll>;
using vi3 = vector<i3>;
using vlii = vector<lii>;
const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9, PI = acos(-1);
int n, m;
char s[N];
char t[N];
int mxPref[N], mxSuff[N];
bool ok(int L) {
  for (int i = 1; i <= n - L + 1; i++) {
    if (mxPref[i - 1] + mxSuff[i + L] >= m) return true;
  }
  return false;
}
void solve(int testCase) {
  scanf("%s %s", s + 1, t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  int p = 1;
  for (int i = 1; s[i]; i++) {
    mxPref[i] = mxPref[i - 1];
    if (s[i] == t[p] && p <= m) {
      mxPref[i]++;
      p++;
    }
  }
  p = m;
  for (int i = n; i >= 1; i--) {
    mxSuff[i] = mxSuff[i + 1];
    if (s[i] == t[p] && p >= 1) {
      mxSuff[i]++;
      p--;
    }
  }
  int low = 0, high = n;
  int ans = 0;
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    if (ok(mid)) {
      ans = mid;
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int testCase = 1; testCase <= t; testCase++) {
    solve(testCase);
  }
  return 0;
}
