#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int bottom[t.size()];
  int t_i = 0;
  for (int i = 0; i < s.size() && t_i < t.size(); ++i) {
    if (s[i] == t[t_i]) {
      bottom[t_i] = i;
      t_i++;
    }
  }
  int top[t.size() + 1];
  top[t.size()] = s.size();
  t_i = (int)t.size() - 1;
  for (int j = (int)s.size() - 1; 0 <= j && 0 <= t_i; --j) {
    if (s[j] == t[t_i]) {
      top[t_i] = j;
      t_i--;
    }
  }
  int space = top[0];
  for (int k = 1; k <= (int)t.size(); ++k) {
    space = max(space, top[k] - bottom[k - 1] - 1);
  }
  cout << space << endl;
}
