#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  string s, t;
  cin >> s >> t;
  vi taken((int)(s).size());
  int ptr = (int)(t).size() - 1;
  for (int i = (int)(s).size() - 1; i >= 0; --i) {
    if (ptr >= 0 and t[ptr] == s[i]) {
      taken[i] = 1;
      ptr--;
    }
  }
  int ans = 0;
  int lptr = -1;
  ptr = -1;
  for (int i = 0; i < (int)(s).size(); ++i) {
    if (taken[i]) {
      ptr++;
      while (true) {
        lptr++;
        if (s[lptr] == t[ptr]) {
          break;
        }
      }
    }
    ans = max(i - lptr, ans);
  }
  cout << ans << endl;
  return 0;
}
