#include <bits/stdc++.h>
using namespace std;
char S[200005], T[200005];
int lenS, lenT;
int pre[200005];
int suf[200005];
int main() {
  int cnt;
  int ans;
  while (~scanf("%s%s", S, T)) {
    ans = 0;
    lenS = strlen(S);
    lenT = strlen(T);
    cnt = 0;
    for (int i = 0; i < lenS; i++) {
      if (S[i] == T[cnt]) cnt++;
      pre[i] = cnt;
      if (cnt == lenT) ans = max(ans, lenS - i - 1);
    }
    cnt = 0;
    for (int i = lenS - 1; i >= 0; i--) {
      if (S[i] == T[lenT - cnt - 1]) cnt++;
      suf[i] = cnt;
      if (cnt == lenT) ans = max(ans, i);
    }
    for (int i = lenS - 1; i >= 0; i--) {
      int x = suf[i];
      int y = lower_bound(pre, pre + lenS, lenT - x) - pre;
      ans = max(ans, i - y - 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
