#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b % a, a);
}
long long int my_pow(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int half = my_pow(a, b / 2);
  long long int ans = (half * half);
  if (b % 2) {
    ans = (ans * a);
  }
  return ans;
}
long long int my_pow_mod_p(long long int a, long long int b, long long int p) {
  if (b == 0) return 1;
  if (b == 1) return a % p;
  long long int half = my_pow(a, b / 2);
  long long int ans = (half * half) % p;
  if (b % 2) {
    ans = (ans * a) % p;
  }
  return ans;
}
class combinatorics {
  long long int N;
  long long int p;
  vector<long long int> fact;
  void cal() {
    fact[0] = 1;
    fact[1] = 1;
    for (long long int i = 2; i < N; i++) {
      fact[i] = (i * fact[i - 1]) % 1000000007;
    }
  }

 public:
  combinatorics(long long int n1, long long int p1) {
    p = p1;
    N = max(n1, 2LL);
    fact.resize(N);
    cal();
  }
  long long int nPr(long long int n, long long int r) {
    if (n < r) {
      return 0;
    }
    long long int val = (fact[n] * my_pow_mod_p(fact[n - r], p - 2, p)) % p;
    return val;
  }
  long long int nCr(long long int n, long long int r) {
    if (n < r) {
      return 0;
    }
    long long int val = nPr(n, r);
    val = (val * my_pow_mod_p(fact[r], p - 2, p)) % p;
    return val;
  }
  long long int get_fact(long long int n) { return fact[n]; }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string str1, str2;
  cin >> str1;
  cin >> str2;
  long long int len1 = str1.length();
  long long int len2 = str2.length();
  vector<vector<long long int> > V(len2, vector<long long int>());
  map<char, vector<long long int> > M;
  for (long long int i = 0; i < len2; i++) {
    char curr_char = str2[i];
    if (M.find(curr_char) == M.end()) {
      M[curr_char] = vector<long long int>();
    }
    M[curr_char].push_back(i);
  }
  for (long long int i = 0; i < len1; i++) {
    char curr_char = str1[i];
    if (M.find(curr_char) != M.end()) {
      long long int len = M[curr_char].size();
      for (long long int j = 0; j < len; j++) {
        V[M[curr_char][j]].push_back(i);
      }
    }
  }
  for (int i = len2 - 2; i >= 0; --i) {
    while (1) {
      long long int last_len = V[i + 1].size();
      long long int len = V[i].size();
      if (V[i][len - 1] >= V[i + 1][last_len - 1]) {
        V[i].pop_back();
      } else {
        break;
      }
    }
  }
  vector<long long int> min_A;
  long long int last_val = V[0][0];
  min_A.push_back(V[0][0]);
  for (long long int i = 1; i < len2; i++) {
    long long int next_idx =
        upper_bound(V[i].begin(), V[i].end(), last_val) - V[i].begin();
    long long int next_val = V[i][next_idx];
    min_A.push_back(next_val);
    last_val = next_val;
  }
  long long int ans = V[0][V[0].size() - 1];
  for (long long int i = 0; i < len2 - 1; i++) {
    long long int next_s = V[i + 1].size();
    ans = max(ans, V[i + 1][next_s - 1] - min_A[i] - 1);
  }
  ans = max(ans, len1 - min_A[len2 - 1] - 1);
  cout << ans << endl;
  return 0;
}
