#include <bits/stdc++.h>
using namespace std;
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long IsPrime(long long n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long)2;
  if (n % 3 == 0)
    return (long long)3;
  else {
    for (long long i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k, i, j;
  string s, t;
  cin >> s >> t;
  n = s.size(), m = t.size();
  vector<long long> fwd(n), bwd(n);
  j = 0;
  for (i = 0; i < n; i++) {
    if (j < m && s[i] == t[j]) {
      j++;
    }
    fwd[i] = j;
  }
  j = m - 1;
  long long c = 0;
  for (i = n - 1; i >= 0; i--) {
    if (j >= 0 && s[i] == t[j]) {
      j--;
      c++;
    }
    bwd[i] = c;
  }
  i = 0;
  j = 0;
  long long ans = 0;
  while (j < n) {
    long long x = 0;
    if (i > 0) x += fwd[i - 1];
    if (j < n - 1) x += bwd[j + 1];
    if (x >= m) {
      ans = max(ans, j - i + 1);
      j++;
    } else {
      i++;
    }
  }
  cout << ans;
}
