#include <bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
  x = 0;
  char ch = getchar();
  long long pd = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') pd = -pd;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= pd;
}
inline void write(const long long &x) {
  char ggg[10001];
  long long s = 0;
  long long tmp = x;
  if (tmp == 0) {
    putchar('0');
    return;
  }
  if (tmp < 0) {
    tmp = -tmp;
    putchar('-');
  }
  while (tmp > 0) {
    ggg[s++] = tmp % 10 + '0';
    tmp /= 10;
  }
  while (s > 0) {
    putchar(ggg[--s]);
  }
}
inline void wrl(const long long &x) {
  write(x);
  putchar('\n');
}
inline void wrs(const long long &x) {
  write(x);
  putchar(' ');
}
long long n, a[400010];
const long long N = 2e5 + 233;
char s[N], g[N];
long long p[N], q[N];
signed main() {
  scanf("%s", s + 1);
  scanf("%s", g + 1);
  long long len1 = strlen(s + 1);
  long long len2 = strlen(g + 1);
  long long now = 1;
  for (register long long i = 1; i <= len1; ++i) {
    if (now <= len2 && s[i] == g[now]) {
      q[now] = i;
      ++now;
    }
  }
  now = len2;
  for (register long long i = len1; i >= 1; --i) {
    if (now >= 1 && s[i] == g[now]) {
      p[now] = i;
      --now;
    }
  }
  long long ans = 0;
  ans = (ans > p[1] - 1 ? ans : p[1] - 1);
  ans = (ans > len1 - q[len2] ? ans : len1 - q[len2]);
  for (register long long i = 1; i < len2; ++i) {
    if (p[i + 1] > q[i])
      ans = (ans > p[i + 1] - q[i] - 1 ? ans : p[i + 1] - q[i] - 1);
  }
  cout << ans << endl;
}
