#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int pos[maxn][2];
string s, t;
int main() {
  ios::sync_with_stdio(false);
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  int j = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == t[j]) pos[j][0] = i, j++;
    if (j == m) break;
  }
  j = m - 1;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == t[j]) pos[j][1] = i, j--;
    if (j == -1) break;
  }
  int ans = max(pos[0][1], n - pos[m - 1][0] - 1);
  for (int i = 1; i < m; ++i) {
    ans = max(pos[i][1] - pos[i - 1][0] - 1, ans);
  }
  printf("%d\n", ans);
  return 0;
}
