#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  vector<int> right(m);
  int cur;
  for (int i = m - 1; i >= 0; i--) {
    cur = n - 1;
    if (i + 1 < m) cur = right[i + 1] - 1;
    while (s[cur] != t[i]) cur--;
    right[i] = cur;
  }
  int ret = 0;
  cur = 0;
  for (int i = 0; i < n; i++) {
    int val = n - 1;
    if (cur < m) val = right[cur] - 1;
    ret = max(ret, val - i + 1);
    if (cur >= m) continue;
    if (t[cur] != s[i]) continue;
    cur++;
  }
  cout << ret << "\n";
  return 0;
}
