#include <bits/stdc++.h>
using namespace std;
const int SZ = 200005;
char s[SZ], t[SZ];
int ld[SZ], rd[SZ];
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  cin >> t;
  int slen = strlen(s), tlen = strlen(t);
  int idx = 0;
  for (int i = 0; i < slen; i++)
    if (idx < tlen && s[i] == t[idx]) ld[idx++] = i;
  idx = tlen - 1;
  for (int i = slen - 1; i >= 0; i--)
    if (idx >= 0 && s[i] == t[idx]) rd[idx--] = i;
  int ans = rd[0];
  for (int i = 0; i < tlen - 1; i++) ans = max(ans, rd[i + 1] - ld[i] - 1);
  ans = max(ans, slen - 1 - ld[tlen - 1]);
  cout << ans;
  return 0;
}
