#include <bits/stdc++.h>
using namespace std;
int f1[200005], f2[200005];
int main() {
  string s, t;
  int sl, tl;
  cin >> s >> t;
  sl = s.length(), tl = t.length();
  int j = 0;
  for (int i = 0; i < sl; i++) {
    if (s[i] == t[j]) f1[j] = i, j++;
    if (j == tl) break;
  }
  f2[tl] = sl;
  j = tl - 1;
  for (int i = sl - 1; i >= 0; i--) {
    if (s[i] == t[j]) f2[j] = i, j--;
    if (j < 0) break;
  }
  int ans = f2[0];
  for (int i = 0; i < tl; i++) {
    ans = max(ans, f2[i + 1] - f1[i] - 1);
  }
  cout << ans;
  return 0;
}
