#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, arr1[200009], arr2[200009], ans;
  char c[200009], d[200009];
  scanf("%s %s", &c, &d);
  n = strlen(c);
  m = strlen(d);
  ans = 0, j = 0;
  for (i = 0; i < n; i++) {
    if (c[i] == d[j]) {
      arr1[j++] = i;
      if (j == m) break;
    }
  }
  j = m - 1;
  for (i = n - 1; i >= 0; i--) {
    if (c[i] == d[j]) {
      arr2[j--] = i;
      if (j == -1) break;
    }
  }
  ans = max(arr2[0], n - 1 - arr1[m - 1]);
  for (i = 1; i < m; i++) ans = max(ans, arr2[i] - arr1[i - 1] - 1);
  cout << ans << endl;
  return 0;
}
