#include <bits/stdc++.h>
using namespace std;
char s[(200000 + 5)], t[(200000 + 5)];
int L[(200000 + 5)], R[(200000 + 5)];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s + 1 >> t + 1;
  int len1 = strlen(s + 1), len2 = strlen(t + 1);
  for (int i = 1, j = 1; i <= len2; i++) {
    while (j <= len1 && s[j] != t[i]) j++;
    L[i] = j++;
  }
  for (int i = len2, j = len1; i; i--) {
    while (j && s[j] != t[i]) j--;
    R[i] = j--;
  }
  int ans = 0;
  for (int i = 1; i <= len2; i++) ans = max(ans, R[i] - L[i - 1] - 1);
  ans = max(ans, len1 - L[len2]);
  cout << ans;
  return 0;
}
