#include <bits/stdc++.h>
using namespace std;
const int maxN = 200005;
char s[maxN], t[maxN];
int lens, lent;
int L[maxN], R[maxN];
int ANS;
int main() {
  scanf("%s%s", &s, &t);
  lens = strlen(s);
  lent = strlen(t);
  for (int i = 0, j = 0; i < lens; i++) {
    if (j < lent && s[i] == t[j]) j++;
    L[i] = j;
  }
  R[lens] = lent - 1;
  for (int i = lens - 1, j = lent - 1; i >= 0; i--) {
    if (j >= 0 && s[i] == t[j]) j--;
    R[i] = j;
  }
  for (int i = 0, j = 0; i <= lens; i++) {
    while (j <= lens && ((i == 0) ? 0 : L[i - 1]) >= R[j] + 1) j++;
    ANS = max(ANS, j - i - 1);
  }
  printf("%d\n", ANS);
  return 0;
}
