#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int x, k, flag, t, ans = 0, j, n, y = 0, m;
  n = a.size();
  m = b.size();
  int arr[m], arr2[m];
  for (int i = 0; i < n; i++) {
    if (a[i] == b[0]) {
      t = i;
      break;
    }
  }
  arr[0] = t;
  k = 1;
  for (int i = t + 1; i < n; i++) {
    if (a[i] == b[k]) {
      arr[k] = i;
      k++;
      if (k == m) {
        break;
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == b[m - 1]) {
      arr2[m - 1] = i;
      m--;
      if (m == 0) {
        break;
      }
    }
  }
  m = b.size();
  for (int i = 0; i < m - 1; i++) {
    ans = max(ans, arr2[i + 1] - arr[i]);
  }
  ans = max(ans, n - arr2[m - 1]);
  ans = max(ans, n - arr[m - 1]);
  ans = max(ans, arr[0] + 1);
  ans = max(ans, arr2[0] + 1);
  cout << ans - 1;
  return 0;
}
