#include <bits/stdc++.h>
using namespace std;
string s, t;
vector<int> pospref, possuf;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  if (s == t) cout << 0, exit(0);
  int ptr = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == t[ptr]) pospref.push_back(i), ptr++;
    if (ptr == t.size()) break;
  }
  ptr = t.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == t[ptr]) possuf.push_back(i), ptr--;
    if (ptr == -1) break;
  }
  reverse(possuf.begin(), possuf.end());
  int ans = -1e9;
  for (int i = 0; i < pospref.size() - 1; ++i)
    ans = max(ans, possuf[i + 1] - pospref[i] - 1);
  cout << max(ans, max(max(pospref[0], possuf[0]),
                       (int)s.size() - pospref[possuf.size() - 1] - 1));
  return 0;
}
