#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 1;
const int base = 1e9 + 7;
template <typename T>
void Read(T& x) {
  bool Neg = false;
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') Neg = !Neg;
  x = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  if (Neg && x > 0) x = -x;
}
long long power(long long a, long long t) {
  if (t == 1) return a;
  long long c = power(a, t / 2);
  if (t % 2 == 1)
    return ((c * c) % base * a) % base;
  else
    return (c * c) % base;
}
int a[maxn];
string s, t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> t;
  int n, m;
  n = s.size();
  m = t.size();
  int ans = 0;
  for (int r = 1; r <= 2; r++) {
    int i = 0, j = 0, res = 0;
    for (int i = 0; i <= n - 1; i++) {
      if (s[i] == t[j]) {
        a[j] = i;
        j++;
      }
      if (j == m) break;
    }
    j = m - 1;
    res = n - a[j] - 1;
    for (i = n - 1; i >= 0; i--) {
      if (s[i] == t[j]) {
        if (j == 0)
          res = max(res, i - 1);
        else
          res = max(res, i - (a[j - 1] + 1));
        j--;
      }
      if (j < 0) break;
    }
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    ans = max(ans, res);
  }
  cout << ans;
}
