#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(int argv, char **argc) {
  string s, t;
  cin >> s >> t;
  int p = s.size() - 1;
  int rg[t.size()];
  for (int i = t.size() - 1; i >= 0; --i) {
    while (s[p] != t[i]) {
      --p;
    }
    rg[i] = p;
    --p;
  }
  p = 0;
  int ans = rg[0];
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == t[p]) {
      int start = i + 1;
      int end;
      if (p == t.size() - 1) {
        end = s.size() - 1;
      } else {
        end = rg[p + 1] - 1;
      }
      ans = max(ans, end - start + 1);
      p++;
      if (p == t.size()) break;
    }
  }
  printf("%d\n", ans);
}
