#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int valder[310010], valiz[310010];
string txt1, txt2;
bool f(int delta) {
  if (valder[delta] >= txt1.size() && delta <= txt2.size()) return 1;
  for (long long i = 0; i < txt2.size(); i++) {
    if (valiz[i] + valder[i + 1 + delta] >= txt1.size() &&
        i + 1 + delta <= txt2.size())
      return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> txt2 >> txt1;
  int posder = txt1.size() - 1;
  int c = 0;
  for (int i = txt2.size() - 1; i >= 0; i--) {
    if (posder >= 0 && txt2[i] == txt1[posder]) c++, posder--;
    valder[i] = c;
  }
  int posiz = 0;
  c = 0;
  for (long long i = 0; i < txt2.size(); i++) {
    if (posiz < txt1.size() && txt2[i] == txt1[posiz]) c++, posiz++;
    valiz[i] = c;
  }
  int iz, der, mid;
  iz = 0, der = txt2.size();
  while (iz + 1 < der) {
    mid = (iz + der) / 2;
    if (f(mid) == 1)
      iz = mid;
    else
      der = mid;
  }
  cout << iz << endl;
}
