#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
const int N = 1000005;
long long int tes, n, m;
string s, t;
vector<long long int> sieve(N, 0);
void si() {
  sieve[1] = 1;
  for (int i = 2; i < N; i++) {
    if (sieve[i] == 0) {
      for (int j = i; j < N; j += i) {
        sieve[j] = i;
      }
    }
  }
}
long long int power(long long int x, long long int y) {
  long long int res = 1ll;
  while (y > 0) {
    if (y & 1) res = res * x;
    y >>= 1;
    x = x * x;
  }
  return res;
}
void solve() {
  cin >> s >> t;
  n = (int)((s).size()), m = (int)((t).size());
  vector<long long int> arr(m), brr(m);
  long long int i = 0, j = 0, ans = 0;
  while (i < n && j < m) {
    if (s[i] == t[j]) {
      arr[j] = i;
      j++;
    }
    i++;
  }
  i = n - 1, j = m - 1;
  while (i >= 0 && j >= 0) {
    if (s[i] == t[j]) {
      brr[j] = i;
      j--;
    }
    i--;
  };
  for (int l = 1; l < m; l++) {
    ans = max(ans, brr[l] - arr[l - 1] - 1);
  }
  ans = max(ans, max(n - arr[m - 1] - 1, brr[0]));
  ans = max(ans, max(arr[0], n - brr[m - 1] - 1));
  cout << ans << "\n";
}
int32_t main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  tes = 1;
  while (tes--) {
    solve();
  }
}
