#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
char s[maxn], t[maxn];
int n, m;
int f[maxn], p[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin >> s + 1 >> t + 1;
  n = strlen(s + 1), m = strlen(t + 1);
  int j = m, ans = 0;
  for (int i = n; i >= 1 && j >= 1;) {
    if (s[i] == t[j]) {
      f[j] = i;
      if (j == 1) ans = max(ans, i - 1);
      j--, i--;
    } else
      i--;
  }
  j = 1;
  for (int i = 1; i <= n && j <= m;) {
    if (s[i] == t[j]) {
      if (j + 1 <= m)
        ans = max(ans, f[j + 1] - i - 1);
      else
        ans = max(ans, n - i);
      i++;
      j++;
    } else
      i++;
  }
  cout << ans << endl;
  return 0;
}
