#include <bits/stdc++.h>
using namespace std;
vector<int> func(string s, string t) {
  int n = s.length(), m = t.length();
  vector<int> arr(m);
  for (int i = 0, l = 0; i < n and l < m; i++) {
    if (s[i] == t[l]) {
      arr[l] = i;
      l++;
    }
  }
  return arr;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t;
  cin >> s;
  cin >> t;
  vector<int> left = func(s, t);
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  vector<int> right = func(s, t);
  int n = s.length() - 1;
  for (int i = 0; i < right.size(); i++) right[i] = n - right[i];
  reverse(right.begin(), right.end());
  int res = max(right[0], n - (int)left.back());
  for (int i = 1; i < t.length(); i++) {
    res = max(res, right[i] - left[i - 1] - 1);
  }
  cout << res << "\n";
}
