#include <bits/stdc++.h>
using namespace std;
int l[200010], r[200010];
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), k = t.size();
  if (s[0] == t[0]) l[0] = 1;
  if (s[n - 1] == t[k - 1]) r[n - 1] = 1;
  for (int i = 1; i < n; i++) {
    if (l[i - 1] < k && s[i] == t[l[i - 1]])
      l[i] = l[i - 1] + 1;
    else
      l[i] = l[i - 1];
    if (r[n - i] < k && s[n - i - 1] == t[k - r[n - i] - 1])
      r[n - i - 1] = r[n - i] + 1;
    else
      r[n - i - 1] = r[n - i];
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (l[i] == k) {
      res = max(res, n - i - 1);
    }
    if (r[i] == k) {
      res = max(res, i);
    }
  }
  int li = 0, ri = 0;
  while (li < n) {
    while (ri < n && r[ri] + l[li] >= k) ri++;
    ri--;
    res = max(ri - li - 1, res);
    li++;
  }
  cout << res << endl;
}
