#include <bits/stdc++.h>
using namespace std;
string s, t;
const int N = 2e5 + 5;
int n, m, L[N], R[N], st[N], en[N];
inline void read_input() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
}
inline void solve() {
  memset(st, -1, sizeof st);
  for (int i = 0, cur = 0; i < n; L[i++] = cur)
    if (cur < m && s[i] == t[cur]) st[++cur] = i;
  fill(en, en + m + 1, n);
  for (int i = n - 1, cur = m; ~i; R[i--] = cur)
    if (cur && s[i] == t[cur - 1]) en[--cur] = i;
}
inline void write_output() {
  int ans = 0;
  for (int i = 0; i <= m; i++) ans = max(ans, en[i] - st[i] - 1);
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read_input(), solve(), write_output();
  return 0;
}
