#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int mod = 998244353;
const int inf = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
char s[MAXN], t[MAXN];
int a[MAXN], aa, b[MAXN], bb, ans = 0;
int main() {
  int i, j, k, len1, len2;
  scanf("%s%s", s, t);
  len1 = strlen(s);
  len2 = strlen(t);
  a[0] = -1;
  for (i = 0; i < len1; i++) {
    if (aa == len2)
      break;
    else {
      if (s[i] == t[aa]) {
        aa++;
        a[aa] = i;
      }
    }
  }
  b[len2] = len1;
  bb = len2 - 1;
  for (i = len1 - 1; i >= 0; i--) {
    if (bb == -1)
      break;
    else {
      if (s[i] == t[bb]) {
        b[bb] = i;
        bb--;
      }
    }
  }
  for (i = 0; i <= len2; i++) ans = max(ans, b[i] - a[i] - 1);
  printf("%d\n", ans);
}
