#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int j = 0, i = 0, maxl = 0, l = 0;
  vector<int> lc, rc;
  while (j < t.size()) {
    if (s[i] == t[j]) {
      j++;
      maxl = max(maxl, l);
      l = 0;
      lc.push_back(i);
    } else
      l++;
    i++;
  }
  int tm = s.size() - i;
  maxl = max(maxl, tm);
  j = t.size() - 1;
  i = s.size() - 1;
  while (j >= 0) {
    if (s[i] == t[j]) {
      j--;
      maxl = max(maxl, l);
      l = 0;
      rc.push_back(i);
    } else
      l++;
    i--;
  }
  maxl = max(i + 1, maxl);
  for (int k = 0; k < t.size() - 1; k++) {
    maxl = max(rc[t.size() - 2 - k] - lc[k] - 1, maxl);
  }
  cout << maxl;
  return 0;
}
