#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int sizea = a.size(), sizeb = b.size();
  int early[sizeb], m = 0, late[sizeb];
  for (int i = 0; i < sizea; i++) {
    if (m == 0 && a[i] == b[m])
      early[m++] = i + 1;
    else if (a[i] == b[m])
      early[m++] = i + 1;
    if (m > sizeb) break;
  }
  m = sizeb - 1;
  for (int i = sizea - 1; i >= 0; i--) {
    if (m == sizeb - 1 && a[i] == b[m])
      late[m--] = i + 1;
    else if (a[i] == b[m])
      late[m--] = i + 1;
    if (m < 0) break;
  }
  int ans = 0;
  for (int i = 0; i < sizeb - 1; i++) {
    ans = max(ans, late[i + 1] - early[i] - 1);
  }
  ans = max(ans, late[0] - 1);
  ans = max(ans, sizea - early[sizeb - 1]);
  printf("%d\n", ans);
  return 0;
}
