#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
using namespace std;
bool solve(string& s, string& t, int len) {
  int j = 0;
  int n = s.size();
  vector<vector<int> > mx(n, vector<int>(2, -inf));
  mx[0][0] = 0;
  if (s[0] == t[0]) {
    if (0 >= len) {
      mx[0][1] = max(mx[0][1], 1);
      mx[0][0] = max(mx[0][0], 1);
    } else
      mx[0][0] = max(mx[0][0], 1);
  }
  for (int i = 1; i < n; ++i) {
    mx[i] = mx[i - 1];
    if (t[mx[i - 1][0]] == s[i]) {
      mx[i][0] = mx[i - 1][0] + 1;
    }
    if (mx[i - 1][1] != -inf && t[mx[i - 1][1]] == s[i])
      mx[i][1] = mx[i - 1][1] + 1;
    if (i - j > len) {
      mx[i][1] = max(mx[i][1], mx[j][0] + (t[mx[j][0]] == s[i]));
      ++j;
    }
    if (s[i] == t[0]) {
      if (i >= len) {
        mx[i][1] = max(mx[i][1], 1);
        mx[i][0] = max(mx[i][0], 1);
      } else
        mx[i][0] = max(mx[i][0], 1);
    }
  }
  for (int z = 0; z < n; ++z) {
    if (mx[z][1] == (int)t.size() - 1) return 1;
  }
  return false;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s, t;
  cin >> s >> t;
  t += '#';
  s += '^';
  int l = 0, r = s.size();
  while (l != r) {
    int mid = (l + r) >> 1;
    if (solve(s, t, mid)) {
      if (l + 1 == r)
        l = r;
      else
        l = mid;
    } else
      r = mid;
  }
  cout << r - 1;
  return 0;
}
