#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char s[N], t[N];
int nw[N], last[N];
int main() {
  scanf("%s%s", s, t);
  int p = 0, n = strlen(s), m = strlen(t);
  for (int i = 0; i < n; ++i) {
    if (s[i] == t[p]) {
      nw[p++] = i;
      if (p == m) break;
    }
  }
  p = m - 1;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == t[p]) {
      last[p--] = i;
      if (p == -1) break;
    }
  }
  int ans = max(last[0], n - nw[m - 1] - 1);
  for (int i = 1; i < m; ++i) {
    if (last[i] > nw[i - 1]) {
      ans = max(ans, last[i] - nw[i - 1] - 1);
    }
  }
  cout << ans << endl;
}
