#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  string s, t;
  cin >> s >> t;
  vector<int> rg(t.size());
  for (int i = int(t.size() - 1); i >= 0; --i) {
    int pose = int(s.size()) - 1;
    if (i + 1 < int(t.size())) pose = rg[i + 1] - 1;
    while (s[pose] != t[i]) --pose;
    rg[i] = pose;
  }
  int ans = 0, pos = 0;
  for (int i = 0; i < int(s.size()); ++i) {
    int temp = int(s.size()) - 1;
    if (pos < int(t.size())) temp = rg[pos] - 1;
    ans = max(ans, temp - i + 1);
    if (pos < t.size() && t[pos] == s[i]) ++pos;
  }
  cout << ans << '\n';
  return 0;
}
