#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAX = 1e6;
int len1, len2, pre[MAX], suf[MAX];
bool can_skip(int skip) {
  for (int i = 1; i + skip - 1 < len1; i++)
    if (pre[i - 1] + suf[i + skip] >= len2) return 1;
  return 0;
}
int main() {
  string x, y, z = "1";
  cin >> x >> y;
  z += x;
  x = z;
  len1 = x.length();
  len2 = y.length();
  for (int i = 1, j = 0, it = 0; i < len1; i++) {
    if (j < len2 && x[i] == y[j]) it++, j++;
    pre[i] = it;
  }
  for (int i = len1 - 1, j = len2 - 1, it = 0; i >= 1; i--) {
    if (j >= 0 && x[i] == y[j]) it++, j--;
    suf[i] = it;
  }
  int l = 0, r = len1, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (can_skip(mid)) {
      l = mid + 1, ans = mid;
    } else
      r = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
