#include <bits/stdc++.h>
using namespace std;
using ll = signed long long int;
using vi = vector<int>;
const int MX = 2e5 + 10;
vi vs, ve;
string l, s;
void fill_vectors() {
  vs.reserve(MX);
  ve.reserve(MX);
  int x = 0;
  for (auto sit = s.begin(), lit = l.begin(); lit != l.end(); lit++) {
    if (sit != s.end() && *sit == *lit) {
      sit++;
      x++;
    }
    vs.push_back(x);
  }
  x = 0;
  for (auto sit = s.rbegin(), lit = l.rbegin(); lit != l.rend(); lit++) {
    if (sit != s.rend() && *sit == *lit) {
      sit++;
      x++;
    }
    ve.push_back(x);
  }
}
int solve() {
  fill_vectors();
  int res = 0, dl, bi, ei = l.length();
  vi::iterator vsit;
  for (auto x : ve) {
    vsit = lower_bound(vs.begin(), vs.end(), s.length() - x);
    if (vsit != vs.end() && *vsit == s.length() - x) {
      bi = vsit - vs.begin() + 1;
      dl = ei - bi - 1;
      if (x == 0 || *vsit == 0) {
        dl++;
      }
    } else {
      dl = ei - 1;
    }
    res = max(res, dl);
    ei--;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  cout.precision(12);
  l.reserve(MX);
  s.reserve(MX);
  cin >> l >> s;
  cout << solve();
}
