#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  return w ? -x : x;
}
char s[301800], t[301800];
int ans, p[301800], q[301800], c[301800], f[301800], d[301800];
signed main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  int n = strlen(s + 1), m = strlen(t + 1);
  d[t[1]] = 1;
  for (int i = 1; i <= n; ++i) {
    p[i] = d[s[i]];
    d[t[p[i] + 1]] = max(d[t[p[i] + 1]], p[i] + 1);
    if (p[i] && !c[p[i]]) c[p[i]] = i;
  }
  reverse(s + 1, s + 1 + n);
  reverse(t + 1, t + 1 + m);
  memset(d, 0, sizeof(d));
  d[t[1]] = 1;
  for (int i = 1; i <= n; ++i) {
    q[i] = d[s[i]];
    d[t[q[i] + 1]] = max(d[t[q[i] + 1]], q[i] + 1);
    if (q[i] && !f[q[i]]) f[q[i]] = i;
  }
  for (int i = 0; i <= m; ++i) {
    ans = max(n - f[i] - c[m - i], ans);
  }
  printf("%d\n", ans);
  return 0;
}
