#include <bits/stdc++.h>
using namespace std;
long long pre[1000000], suf[1000000];
int main() {
  string x, y;
  cin >> x >> y;
  int n = x.length(), m = y.length();
  for (int i = 0, j = 0; i < n && j < m; i++) {
    if (x[i] == y[j]) {
      pre[j] = i;
      j++;
    }
  }
  for (int i = n - 1, j = m - 1; i >= 0 && j >= 0; i--) {
    if (x[i] == y[j]) {
      suf[j] = i;
      j--;
    }
  }
  long long ma = max(suf[0], n - pre[m - 1] - 1);
  for (int i = 1; i < m; i++) {
    ma = max(ma, (suf[i] - pre[i - 1]) - 1);
  }
  cout << ma << endl;
  return 0;
}
