#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 1e9 + 7;
const int alphabet = 26;
const int inf = INT_MAX;
const long long linf = 1e18 + 9;
namespace util {
inline long long cnm(char ch) { return (ch - '0'); }
inline long long cap(char ch) { return (ch - 'a'); }
inline void instr(string& s, long long& n) {
  cin >> s;
  n = s.length();
}
inline void instr(string& s) { cin >> s; }
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
bool min(T a, T b, T c) {
  return std::min(a, std::min(b, c));
}
}  // namespace util
using namespace util;
int leftmost[maxn], rightmost[maxn];
void solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, m, n;
  string s, t;
  instr(s, n);
  instr(t, m);
  int idx = 0;
  for (i = 0; i < n; i++) {
    if (idx < m and s[i] == t[idx]) {
      leftmost[idx] = i;
      idx++;
    }
  }
  idx = m - 1;
  for (i = n - 1; i >= 0; i--) {
    if (idx >= 0 and t[idx] == s[i]) {
      rightmost[idx] = i;
      idx--;
    }
  }
  long long ans = rightmost[0];
  ans = max(ans, n - 1 - leftmost[m - 1]);
  for (i = 1; i < m; i++) {
    long long cur = rightmost[i] - leftmost[i - 1] - 1;
    ans = max(ans, cur);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
