#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9) + 7;
const long double EPS = 0.0000001;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  string t;
  cin >> t;
  int szs = s.size();
  int szt = t.size();
  int cur = 0;
  int pref[szt + 1];
  int suff[szt + 1];
  for (int i = 0; i < szs; i++) {
    if (s[i] == t[cur]) {
      pref[cur] = i;
      cur++;
    }
    if (cur == szt) break;
  }
  cur--;
  for (int i = szs - 1; i >= 0; i--) {
    if (s[i] == t[cur]) {
      suff[cur] = i;
      cur--;
    }
    if (cur == -1) break;
  }
  int ans = 0;
  ans = max(ans, szs - 1 - suff[szt - 1]);
  ans = max(ans, suff[0]);
  ans = max(ans, pref[0]);
  ans = max(ans, szs - 1 - pref[szt - 1]);
  for (int i = 0; i < szt - 1; i++) {
    ans = max(ans, suff[i + 1] - pref[i] - 1);
  }
  cout << ans << endl;
  return 0;
}
