#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
int pos[N];
char s[N];
char t[N];
int main() {
  scanf("%s %s", s + 1, t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  for (int i = 1, j = 1; i <= m; i++) {
    while (s[j] != t[i]) {
      j++;
    }
    pos[i] = j++;
  }
  int ans = 0;
  for (int i = n, j = m; i; i--) {
    ans = max(ans, i - pos[j]);
    if (s[i] == t[j]) {
      j--;
    }
  }
  printf("%d\n", ans);
}
