#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  string temp;
  int l = t.size();
  int n = s.size();
  int ans = 0;
  vector<int> v(l);
  for (int i = l - 1; i >= 0; i--) {
    int pos = n - 1;
    if (i + 1 < l) pos = v[i + 1] - 1;
    while (s[pos] != t[i]) pos--;
    v[i] = pos;
  }
  int pos = ans = 0;
  for (int i = 0; i < n; i++) {
    int rpos = n - 1;
    if (pos < l) rpos = v[pos] - 1;
    ans = max(ans, rpos - i + 1);
    if (pos < l && s[i] == t[pos]) pos++;
  }
  cout << ans << endl;
}
