#include <bits/stdc++.h>
using namespace std;
long long n, m;
string str1, str2;
long long pre1[2000005], pre2[2000005];
inline void init() {
  cin >> str1 >> str2;
  n = str1.size();
  m = str2.size();
}
inline void solve() {
  long long i = 0, j = 0;
  while (i < n && j < m) {
    while (str1[i] != str2[j]) ++i;
    pre1[j] = i;
    ++i, ++j;
  }
  i = n - 1, j = m - 1;
  while (i >= 0 && j >= 0) {
    while (str1[i] != str2[j]) --i;
    pre2[j] = i;
    --i, --j;
  }
}
signed main() {
  init();
  solve();
  long long ans = 0;
  for (long long i = 0; i < m - 1; i++) {
    ans = max(ans, pre2[i + 1] - pre1[i] - 1);
  }
  ans = max(ans, pre2[0]);
  ans = max(ans, n - pre1[m - 1] - 1);
  printf("%lld", ans);
  return 0;
}
