#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long arr[1000000];
long long n, q, c, cnt, mx, m, temp, k;
string str;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first < b.first);
}
vector<long long> primeFactors(long long n) {
  vector<long long> ans;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        ans.push_back(i);
      else {
        ans.push_back(i);
        ans.push_back(n / i);
      }
    }
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  bool readfromfile = false;
  if (!readfromfile) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  } else {
    freopen("/Users/amrfahmy/Documents/Problem solving/CF/CF/input.txt", "r",
            stdin);
  }
  string s, t;
  cin >> s;
  cin >> t;
  int slen = (int)s.length();
  int tlen = (int)t.length();
  vector<int> right(tlen, 0);
  for (int i = tlen - 1; i >= 0; i--) {
    int r = slen - 1;
    if (i + 1 < tlen) r = right[i + 1] - 1;
    while (s[r] != t[i]) r--;
    right[i] = r;
  }
  int pos = 0, ans = 0;
  for (int i = 0; i < slen; i++) {
    if (pos >= tlen)
      ans = max(ans, slen - i);
    else
      ans = max(ans, right[pos] - i);
    if (pos < tlen && t[pos] == s[i]) pos++;
  }
  cout << ans;
  return 0;
}
