#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  char s[200005];
  char t[200005];
  cin >> s;
  cin >> t;
  int ls = strlen(s);
  int lt = strlen(t);
  int rm[200005];
  rm[lt] = ls;
  int i, j;
  for (i = lt - 1; i >= 0; i--) {
    for (j = rm[i + 1] - 1; j >= 0; j--) {
      if (s[j] == t[i]) {
        rm[i] = j;
        break;
      }
    }
  }
  int ans = 0;
  j = 0;
  for (i = 0; i < lt; i++) {
    for (; j < ls; j++) {
      if (t[i] == s[j]) {
        break;
      }
    }
    ans = max(ans, rm[i + 1] - j - 1);
    j++;
  }
  ans = max(ans, rm[0]);
  cout << ans << endl;
  return 0;
}
