#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int expo(int x, int y) {
  int res = 1;
  x = x % M;
  while (y > 0) {
    if (y & 1) res = (1ll * res * x) % M;
    y = y >> 1;
    x = (1ll * x * x) % M;
  }
  return res;
}
int ncr(int n, int r) {
  int res = 1;
  if (r > n - r) r = n - r;
  for (int i = 0; i < r; i++) {
    res *= n - i;
    res /= i + 1;
  }
  return res;
}
bool prime(long long n) {
  long long i;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    int n1, n2, i, j, mx = 0;
    string s1, s2;
    vector<int> v1, v2;
    cin >> s1 >> s2;
    n1 = s1.size();
    n2 = s2.size();
    for (i = 0, j = 0; i < n1 && j < n2; i++) {
      if (s1[i] == s2[j]) {
        v1.push_back(i);
        j++;
      }
    }
    for (i = n1 - 1, j = n2 - 1; i >= 0 && j >= 0; i--) {
      if (s1[i] == s2[j]) {
        v2.push_back(i);
        j--;
      }
    }
    reverse(v2.begin(), v2.end());
    mx = max(mx, v2[0]);
    for (i = 0; i < n2 - 1; i++) {
      mx = max(mx, v2[i + 1] - v1[i] - 1);
    }
    mx = max(mx, n1 - 1 - v1[n2 - 1]);
    cout << mx;
  }
  return 0;
}
