#include <bits/stdc++.h>
using namespace std;
char str1[200000 + 7], str2[200000 + 7];
int prefix[200000 + 7], suffix[200000 + 7], min_index[200000 + 7];
int main() {
  int len1, len2;
  scanf("%s", str1);
  scanf(" %s", str2);
  len1 = strlen(str1);
  len2 = strlen(str2);
  int match = 0, ans = 0;
  min_index[0] = -1;
  for (int i = 0; i < len1; i++) {
    if (match < len2 and str2[match] == str1[i]) {
      match++;
      min_index[match] = i;
      if (match == len2) ans = len1 - i - 1;
    }
    prefix[i] = match;
  }
  match = len2 - 1;
  for (int i = len1 - 1; i >= 0; i--) {
    if (match >= 0 and str2[match] == str1[i]) {
      match--;
    }
    int m = len2 - match - 1;
    int rem = len2 - m;
    ans = max(ans, i - min_index[rem] - 1);
  }
  printf("%d\n", ans);
  return 0;
}
