#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int a[200005], b[200005];
  int j = 0;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == t[j]) {
      a[j] = i;
      j++;
      if (j == t.length()) break;
    }
  j = t.length() - 1;
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == t[j]) {
      b[j] = i;
      j--;
      if (j < 0) break;
    }
  int ans = b[0];
  for (int i = 0; i < t.length() - 1; i++)
    ans = max(ans, (b[i + 1] - a[i] - 1));
  int n = t.length() - 1;
  if (ans < s.length() - a[n] - 1) ans = s.length() - a[n] - 1;
  cout << ans;
  return 0;
}
