#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int n, m, k, t;
char a[200505], b[200505];
int now[200505][3];
int main() {
  cin >> (a + 1) >> (b + 1);
  int lena = strlen(a + 1);
  int lenb = strlen(b + 1);
  int maxm = 0;
  for (int i = 1, j = 1; i <= lena; i++) {
    if (a[i] == b[j]) {
      now[j][1] = i;
      j++;
      if (j > lenb) {
        maxm = max(lena - i, maxm);
        break;
      }
    }
  }
  for (int i = lena, j = lenb; i >= 1; i--) {
    if (a[i] == b[j]) {
      now[j][2] = i;
      j--;
      if (j == 0) {
        maxm = max(i - 1, maxm);
        break;
      }
    }
  }
  for (int i = 2; i <= lenb; i++) {
    maxm = max(maxm, now[i][2] - now[i - 1][1] - 1);
  }
  cout << maxm << endl;
}
