#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  ;
  string S, T;
  cin >> S >> T;
  vector<long long int> Dat(T.length());
  for (long long int i = T.length() - 1; i >= (long long int)0; i--) {
    long long int Ind = S.length() - 1;
    if (i + 1 < T.length()) Ind = Dat[i + 1] - 1;
    while (S[Ind] != T[i]) Ind--;
    Dat[i] = Ind;
  }
  long long int Res = 0, Ind = 0;
  for (long long int i = 0; i < (long long int)S.length(); i++) {
    long long int R = S.length() - 1;
    if (Ind < T.length()) R = Dat[Ind] - 1;
    Res = max(Res, R - i + 1);
    if (Ind < T.length() && T[Ind] == S[i]) Ind++;
  }
  cout << Res << endl;
}
