#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 10;
char s[maxx], t[maxx];
int l[maxx], r[maxx];
int main() {
  cin >> s >> t;
  int m = strlen(s);
  int n = strlen(t);
  int a = 0, b = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == t[a]) {
      l[a] = i;
      a++;
    }
    if (a == n) break;
  }
  for (int i = m - 1; i >= 0; i--) {
    if (s[i] == t[n - b - 1]) {
      r[b] = i;
      b++;
    }
    if (b == n) break;
  }
  int ans = max(r[n - 1], m - l[n - 1] - 1);
  for (int i = 0; i < n; i++) ans = max(ans, r[i] - l[n - i - 2] - 1);
  cout << ans << endl;
}
