#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  if (s == t) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> last_idx;
  for (int i = s.length() - 1, j = t.length() - 1; i >= 0 && j >= 0; i--) {
    if (s[i] == t[j]) {
      last_idx.push_back(i);
      j--;
    }
  }
  reverse(last_idx.begin(), last_idx.end());
  auto C = [&](int mid) {
    string pre;
    int len = 0;
    for (int i = mid; i < s.length(); i++) {
      int idx = len;
      int ll = t.length() - (lower_bound(last_idx.begin(), last_idx.end(), i) -
                             last_idx.begin());
      if (idx + ll >= t.length()) return true;
      if (s[i - mid] == t[len]) {
        pre += s[i - mid];
        len += 1;
      }
    }
    if (pre == t) return true;
    return false;
  };
  int lb = 1, ub = s.length() - t.length() + 1;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }
  cout << lb << '\n';
  return 0;
}
