#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int m = t.length();
  int a[m], b[m];
  int i = 0, k = 0;
  while (i < n && k < m) {
    if (t[k] == s[i]) {
      a[k] = i;
      k++;
    }
    i++;
  }
  i = n - 1;
  k = m - 1;
  while (i >= 0 && k >= 0) {
    if (t[k] == s[i]) {
      b[k] = i;
      k--;
    }
    i--;
  }
  int maximum;
  maximum = max(a[0], n - b[m - 1] - 1);
  maximum = max(maximum, max(n - 1 - a[m - 1], b[0]));
  for (int i = 0; i < m - 1; i++) {
    maximum = max(maximum, b[i + 1] - a[i] - 1);
  }
  cout << maximum << endl;
  return 0;
}
