#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int INF = 2e9;
char s[maxn], ss[maxn];
int f[maxn], ff[maxn];
int main() {
  cin >> s;
  getchar();
  cin >> ss;
  int len1 = strlen(s);
  int len2 = strlen(ss);
  for (int i = 0, j = 0; i < len1; i++)
    if (j < len2 && s[i] == ss[j]) f[j++] = i;
  for (int i = len1 - 1, j = len2 - 1; i >= 0; i--)
    if (j >= 0 && s[i] == ss[j]) ff[j--] = i;
  int ans = max(len1 - f[len2 - 1] - 1, ff[0]);
  for (int i = 0; i < len2 - 1; i++) ans = max(ans, ff[i + 1] - f[i] - 1);
  cout << ans << endl;
}
