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