#include <bits/stdc++.h>
const long long int mod = 998244353;
const long long int inf = 100000000000;
using namespace std;
void solve(int aaabbbb) {
  string s, t;
  cin >> s >> t;
  long long int n = s.length(), m = t.length();
  long long int last[n + 1], first[n + 1], j = 0;
  first[0] = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == t[j]) first[j] = i, j++;
    if (j == m) break;
  }
  j = m - 1;
  last[m] = m;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == t[j]) last[j] = i, j--;
    if (j == -1) break;
  }
  long long int best = max(last[0], n - first[m - 1] - 1);
  for (int i = 1; i < m; i++) {
    best = max(best, last[i] - first[i - 1] - 1);
  }
  cout << best;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
