#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int dp[N], f[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string t, s;
  cin >> s >> t;
  s = "$" + s + "$";
  t = "$" + t + "$";
  int n = s.size(), i;
  for (i = 1; i < n - 1; i++) {
    if (t[dp[i - 1] + 1] == s[i]) {
      dp[i] = dp[i - 1] + 1;
      f[dp[i]] = i;
    } else
      dp[i] = dp[i - 1];
  }
  dp[n] = t.size() - 1;
  int ans = 0;
  for (i = n - 1; i > 0; i--) {
    if (t[dp[i + 1] - 1] == s[i])
      dp[i] = dp[i + 1] - 1;
    else
      dp[i] = dp[i + 1];
    ans = max(ans, i - f[dp[i] - 1] - 1);
  }
  cout << ans << '\n';
}
