#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long power(long long a, long long b, long long modi) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % modi;
    }
    b /= 2;
    a = (a * a) % modi;
  }
  return res;
}
int a[200005], b[200005], n, m;
string s, t;
int first[200005], last[200005];
void fun1() {
  int i = 0, j = 0;
  while (i < n) {
    if (j < m && s[i] == t[j]) {
      first[j] = i;
      j++;
    }
    i++;
  }
}
void fun2() {
  int i = n - 1, j = m - 1;
  while (i >= 0) {
    if (j >= 0 && s[i] == t[j]) {
      last[j] = i;
      j--;
    }
    i--;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  n = s.length();
  m = t.length();
  fun1();
  fun2();
  int ans = max(last[0], n - first[m - 1] - 1);
  for (int i = 0; i < m - 1; i++) {
    int cur = n - (first[i] + 1 + n - last[i + 1]);
    ans = max(ans, cur);
  }
  cout << ans;
  return 0;
}
