#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int x = s1.size(), y = s2.size();
  while (y && x) {
    if (s1[x - 1] == s2[y - 1]) {
      a[y] = x;
      y--;
    }
    x--;
  }
  y = 1;
  a[s2.size() + 1] = s1.size() + 1;
  int res = a[1] - 1;
  for (int i = 0; i < s1.size(); ++i) {
    if (s1[i] == s2[y - 1]) {
      res = max(res, a[y + 1] - i - 2);
      y++;
    }
  }
  cout << res;
}
