#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
template <typename T>
inline T read(T& x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = f ? -x : x;
}
const int maxn = 2e5 + 9;
char s[maxn], t[maxn];
int pre[maxn], las[maxn];
int main() {
  scanf("%s%s", s, t);
  int slen = strlen(s);
  int tlen = strlen(t);
  int ans = 0;
  int cur = 0;
  int id = 0;
  for (int i = 0; i < slen; i++) {
    if (cur < tlen && s[i] == t[cur]) {
      pre[cur] = i;
      cur++;
    }
  }
  cur = tlen - 1;
  for (int i = slen - 1; i >= 0; i--) {
    if (cur >= 0 && s[i] == t[cur]) {
      las[cur] = i;
      cur--;
    }
  }
  for (int i = 0; i < tlen; i++) {
    int tmp;
    if (i == 0) {
      tmp = las[i];
    } else {
      tmp = las[i] - pre[i - 1] - 1;
    }
    ans = max(ans, tmp);
  }
  int tmp = slen - pre[tlen - 1] - 1;
  ans = max(ans, tmp);
  printf("%d\n", ans);
  return 0;
}
