#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int l = b.size();
  int st = a.size() - 1;
  int ar[l + 3];
  memset(ar, -1, sizeof ar);
  ar[l] = st + 1;
  for (int i = l - 1; i >= 0; i--) {
    while (st >= 0 && a[st] != b[i]) {
      st--;
    }
    if (st >= 0) {
      ar[i] = st;
      st--;
    } else
      break;
  }
  int ans = 0;
  int pre = 0;
  for (int i = 0; i < a.size(); i++) {
    int la = ar[pre];
    if (la != -1) ans = max(ans, la - i);
    if (pre < l && a[i] == b[pre]) {
      pre++;
    }
  }
  cout << ans << endl;
  return 0;
}
