#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long max_n = 100005;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  long long prefix[t.length()], suffix[t.length()];
  long long index = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == t[index]) {
      prefix[index] = i;
      index++;
      if (index == t.length()) {
        break;
      }
    }
  }
  index = t.length() - 1;
  for (long long i = s.length() - 1; i >= 0; i--) {
    if (s[i] == t[index]) {
      suffix[index] = i;
      index--;
      if (index < 0) {
        break;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < t.length() - 1; i++) {
    long long alpha = prefix[i];
    long long beta = suffix[i + 1];
    ans = max(ans, beta - alpha - 1);
  }
  ans = max(ans, suffix[0]);
  long long alpha = s.length();
  ans = max(ans, alpha - prefix[t.length() - 1] - 1);
  cout << ans;
  return 0;
}
