#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n) {
  a %= 1000000007;
  if (n == 1) return a;
  if (n == 0) return 1;
  if (n % 2)
    return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007;
  return power((a * a) % 1000000007, n / 2) % 1000000007;
}
const long long inf = (long long)1e18;
long long inverse(long long x) { return power(x, 1000000007 - 2) % 1000000007; }
long long lind[200005], rind[200005];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  string s, t;
  cin >> s >> t;
  long long it = 0;
  for (long long i = 0; i < (long long)t.size(); ++i) {
    while (it < (long long)s.size() && s[it] != t[i]) {
      ++it;
    }
    lind[i] = it++;
  }
  it = (long long)s.size() - 1;
  for (long long i = (long long)t.size() - 1; i > -1; --i) {
    while (it - 1 >= 0 && s[it] != t[i]) {
      --it;
    }
    rind[i] = it--;
  }
  long long ans =
      max(rind[0], (long long)s.size() - 1 - lind[(long long)t.size() - 1]);
  for (long long i = 1; i < (long long)t.size(); ++i) {
    ans = max(ans, rind[i] - lind[i - 1] - 1);
  }
  cout << ans;
  return 0;
}
