#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3e5 + 100;
const long long INF = 1e18;
const long long MOD = 998244353;
void solve() {
  string a, b;
  cin >> a >> b;
  long long n = a.size();
  vector<long long> left(n + 4), right(n + 4);
  long long kol = 0;
  for (int i = 1; i <= n; i++) {
    if (kol < b.size() && b[kol] == a[i - 1]) kol++;
    left[i] = kol;
  }
  kol = 0;
  for (int i = n; i > 0; i--) {
    if (kol < b.size() && b[b.size() - kol - 1] == a[i - 1]) kol++;
    right[i] = kol;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long l = i, r = n + 1;
    while (l < r) {
      long long c = (l + r + 1) >> 1;
      if (left[i - 1] + right[c] < b.size())
        r = c - 1;
      else
        l = c;
    }
    ans = max(ans, l - i);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long test = 1;
  while (test--) solve();
  return 0;
}
