#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, M = 2e5 + 7;
long long powe(long long x, long long y) {
  x = x % mod, y = y % (mod - 1);
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
int l[M], r[M];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string a, b;
  cin >> a >> b;
  int l1 = a.length();
  int l2 = b.length();
  int p1, p2 = l2 - 1, ctr = 0;
  for (int i = l1 - 1; i >= 0; i--) {
    if (p2 >= 0 && a[i] == b[p2]) {
      ctr++;
      p2--;
    }
    l[i] = ctr;
  }
  p2 = 0, ctr = 0;
  for (int i = 0; i < l1; i++) {
    if (p2 < l2 && a[i] == b[p2]) {
      p2++;
      ctr++;
    }
    r[i] = ctr;
  }
  int maxi = 0;
  p1 = 0, p2 = 0;
  while (p1 < l1) {
    while (p2 < l1 && r[p1] + l[p2 + 1] >= l2) p2++;
    maxi = max(maxi, p2 - p1 - 1);
    p1++;
  }
  for (int i = l1 - 1; i >= 0; i--) {
    if (l[i] >= l2) {
      maxi = max(maxi, i);
      break;
    }
  }
  cout << maxi;
  return 0;
}
