#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int lenS, lenT;
char s[N], t[N];
int prefix[N], suffix[N];
int main() {
  scanf("%s %s", s + 1, t + 1);
  lenS = strlen(s + 1), lenT = strlen(t + 1);
  for (int i = 1, pos = 0; i <= lenS; i++) {
    if (s[i] == t[pos + 1]) pos++;
    prefix[i] = pos;
  }
  for (int i = lenS, pos = lenT + 1; i >= 0; i--) {
    if (s[i] == t[pos - 1]) pos--;
    suffix[i] = pos;
  }
  suffix[lenS + 1] = lenT + 1;
  suffix[lenS + 2] = 999999999;
  int ans = 0;
  for (int i = 0, l = 0, r = 0; i <= lenT; i++) {
    while (prefix[l] < i) l++;
    while (suffix[r] < i + 2) r++;
    r--;
    ans = max(ans, r - l - 1);
  }
  printf("%d\n", ans);
}
