#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 10;
string s, t;
int d[N];
int LastSeen[N];
void input() {
  cin >> s >> t;
  return;
}
void PrePros() {
  int keep = (int)(t.size()) - 1, pnt = (int)(s.size()) - 1;
  while (keep >= 0) {
    if (s[pnt] == t[keep]) {
      LastSeen[keep] = pnt;
      keep--;
    }
    pnt--;
  }
  LastSeen[t.size()] = s.size();
  t.push_back('*');
  return;
}
void solve() {
  PrePros();
  int lastfound = 0;
  for (int i = 0; i < s.size(); i++) {
    d[i] = LastSeen[lastfound] - i;
    if (s[i] == t[lastfound]) lastfound++;
  }
  return;
}
void output() {
  int ans = 0;
  for (int i = 0; i < s.size(); i++) ans = max(ans, d[i]);
  cout << ans << endl;
  return;
}
int main() {
  input();
  solve();
  output();
  return 0;
}
