#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s1, s2;
  int n, i, j, k, p, ans, m;
  cin >> s1 >> s2;
  n = s2.length();
  m = s1.length();
  vector<int> a(n), b(n);
  p = 0;
  for (i = 0; i < s1.length(); i++) {
    if (s1[i] == s2[p]) a[p++] = i;
    if (p == n) break;
  }
  p = n - 1;
  for (i = s1.length() - 1; i >= 0; i--) {
    if (s1[i] == s2[p]) b[p--] = i;
    if (p < 0) break;
  }
  ans = max(a[0], m - 1 - b[n - 1]);
  ans = max(ans, m - 1 - a[n - 1]);
  ans = max(ans, b[0]);
  for (i = 1; i < n; i++) ans = max(ans, b[i] - a[i - 1] - 1);
  cout << ans << "\n";
  return 0;
}
