#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn], t[maxn];
int pre[maxn], suf[maxn];
int len1, len2;
int main() {
  scanf("%s%s", s + 1, t + 1);
  len1 = strlen(s + 1);
  len2 = strlen(t + 1);
  int pos = 1;
  for (int i = 1; i <= len1; i++) {
    if (t[pos] == s[i]) {
      pre[pos] = i;
      pos++;
    }
  }
  pos = len2;
  for (int i = len1; i >= 1; i--) {
    if (t[pos] == s[i]) {
      suf[pos] = i;
      pos--;
    }
  }
  int ans = 0;
  suf[len2 + 1] = len1 + 1;
  pre[0] = 0;
  for (int i = 0; i <= len2; i++) ans = max(ans, suf[i + 1] - pre[i] - 1);
  printf("%d\n", ans);
  return 0;
}
