#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
signed main() {
  std::ios::sync_with_stdio(false);
  string second, t;
  cin >> second >> t;
  if (second.compare(t) == 0) cout << 0, exit(0);
  long long int n = second.size();
  long long int m = t.size();
  vector<long long int> pref(n);
  vector<long long int> postf(n);
  long long int i = 0, j = 0;
  while (i < n) {
    if (second[i] == t[j])
      pref[i] = j + 1, i++, j++, j = min(m - 1, j);
    else
      pref[i] = pref[max(0ll, i - 1)], i++;
  }
  i = n - 1, j = m - 1;
  while (i > -1) {
    if (second[i] == t[j])
      postf[i] = m - j, i--, j--, j = max(0ll, j);
    else
      postf[i] = postf[min(n - 1, i + 1)], i--;
  }
  42;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (i == 0) {
      if (postf[1] >= m) ans = max(ans, 1ll);
    } else {
      long long int diff = 0;
      if (i == n - 1)
        diff = m;
      else
        diff = m - postf[i + 1];
      if (diff == 0)
        ans = max(ans, i + 1);
      else {
        long long int indx =
            lower_bound(pref.begin(), pref.end(), diff) - pref.begin();
        ans = max(ans, i - indx);
      }
    }
  }
  cout << ans << "\n";
}
