#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int sizeT = t.size();
  int sizeS = s.size();
  vector<int> indices1(sizeT);
  vector<int> indices2(sizeT);
  int indexS = 0;
  int indexT = 0;
  while (indexT < sizeT) {
    while (s[indexS] != t[indexT]) {
      indexS++;
    }
    indices1[indexT] = indexS;
    indexT++;
    indexS++;
  }
  indexS = sizeS - 1;
  indexT = sizeT - 1;
  while (indexT >= 0) {
    while (s[indexS] != t[indexT]) {
      indexS--;
    }
    indices2[indexT] = indexS;
    indexT--;
    indexS--;
  }
  int res = max(indices2[0], sizeS - indices1[sizeT - 1] - 1);
  for (int i = 1; i < sizeT; i++) {
    res = max(res, indices2[i] - indices1[i - 1] - 1);
  }
  cout << res << endl;
}
