#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = (int)2e5 + 5;
  string s, t;
  int d[N], last[N];
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  int idx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[idx]) {
      d[idx] = i;
      idx++;
    }
  }
  idx = m - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == t[idx]) {
      last[idx] = i;
      idx--;
    }
  }
  int ans = max(last[0], n - 1 - d[m - 1]);
  for (int i = 1; i < m; i++) {
    ans = max(ans, last[i] - d[i - 1] - 1);
  }
  cout << ans << "\n";
}
