#include <bits/stdc++.h>
template <typename T>
void scan(T &x) {
  x = 0;
  register bool _ = 0;
  register T c = getchar();
  _ = c == 45;
  c = _ ? getchar() : c;
  while (c < 48 || c > 57) c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  x = _ ? -x : x;
}
template <typename T>
void printn(T n) {
  register bool _ = 0;
  _ = n < 0;
  n = _ ? -n : n;
  char snum[65];
  int i = 0;
  do {
    snum[i++] = n % 10 + 48;
    n /= 10;
  } while (n);
  --i;
  if (_) putchar(45);
  while (i >= 0) putchar(snum[i--]);
}
template <typename First, typename... Ints>
void scan(First &arg, Ints &...rest) {
  scan(arg);
  scan(rest...);
}
template <typename T>
void print(T n) {
  printn(n);
  putchar(10);
}
template <typename First, typename... Ints>
void print(First arg, Ints... rest) {
  printn(arg);
  putchar(32);
  print(rest...);
}
using namespace std;
const int MM = 2e5 + 5;
char s[MM], t[MM];
int n, m, st[MM], ed[MM];
int ans;
int main() {
  scanf("%s %s", s + 1, t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  int id = 1;
  for (int i = 1; i <= m; i++) {
    while (s[id] != t[i]) {
      id++;
      assert(id <= n);
    }
    st[i] = id;
    id++;
  }
  id = n;
  for (int i = m; i > 0; i--) {
    while (s[id] != t[i]) {
      id--;
      assert(id > 0);
    }
    ed[i] = id;
    id--;
  }
  for (int i = 1; i <= m; i++) {
    ans = max(ans, ed[i] - st[i - 1] - 1);
  }
  ans = max(ans, n + 1 - st[m] - 1);
  print(ans);
  return 0;
}
