#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int x = t.length();
  vector<int> lft(x);
  vector<int> rgt(x);
  int l = 0;
  for (int i = 0; i < n && l < x; ++i) {
    if (s[i] == t[l]) {
      lft[l++] = i;
    }
  }
  l = x - 1;
  for (int i = n - 1; i >= 0 && l >= 0; --i) {
    if (s[i] == t[l]) {
      rgt[l--] = i;
    }
  }
  int mx = 0;
  mx = max(mx, lft[0]);
  mx = max(mx, rgt[0]);
  mx = max(mx, n - 1 - lft[x - 1]);
  mx = max(mx, n - 1 - rgt[x - 1]);
  for (int i = 1; i < x; ++i) mx = max(mx, rgt[i] - lft[i - 1] - 1);
  cout << mx;
}
