#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N], t[N];
int vis[N], vs[N];
int main() {
  cin >> s + 1 >> t + 1;
  int j = 1;
  int n = strlen(s + 1);
  int m = strlen(t + 1);
  for (int i = 1; i <= n && j <= m; ++i) {
    if (s[i] == t[j]) {
      vis[j] = i;
      ++j;
    }
  }
  j = m;
  for (int i = n; i >= 1 && j >= 1; --i) {
    if (s[i] == t[j]) {
      vs[j] = i;
      --j;
    }
  }
  int ans = max(vis[1] - 1, n - vis[m]);
  ans = max(ans, vs[1] - 1);
  ans = max(ans, n - vs[m]);
  for (int i = 1; i <= m; ++i) {
    ans = max(ans, vs[i] - vis[i - 1] - 1);
  }
  printf("%d\n", ans);
}
