#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int k, ans, l, r, lena, lenb, c[N], d[N];
char a[N], b[N];
int main() {
  cin >> a >> b;
  lena = strlen(a);
  lenb = strlen(b);
  for (int i = 0; i < lena; i++) {
    if (b[k] == a[i]) {
      c[k] = i;
      k++;
    }
    if (k == lenb) {
      l = i;
      break;
    }
  }
  k = lenb - 1;
  for (int i = lena - 1; i >= 0; i--) {
    if (b[k] == a[i]) {
      d[k] = i;
      k--;
    }
    if (k == -1) {
      r = i;
      break;
    }
  }
  ans = max(r, lena - 1 - l);
  for (int i = 1; i < lenb; i++) ans = max(ans, d[i] - c[i - 1] - 1);
  cout << ans << endl;
  return 0;
}
