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