#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string t, s;
  cin >> t >> s;
  vector<vector<int>> adj(28);
  vector<int> dp(t.size(), 1);
  for (int i = 0; i < t.size(); ++i) adj[t[i] - 'a'].emplace_back(i);
  vector<pair<int, int>> pr;
  for (int i = 1; i < s.size(); ++i)
    for (auto p : adj[s[i] - 'a'])
      if (p - 1 >= 0 && t[p - 1] == s[i - 1]) dp[p] += dp[p - 1];
  for (int i = 0; i < t.size(); ++i)
    if (dp[i] == s.size() && t[i] == s.back())
      pr.emplace_back(i - dp[i] + 1, i);
  int ans = 0;
  for (auto p : pr) ans = max({ans, p.first, (int)t.size() - p.second - 1});
  int i = 0, j = t.size() - 1, l = 0, r = s.size() - 1;
  while (i < t.size() && l < s.size() && t[i] == s[l]) ++i, ++l;
  while (j >= 0 && r >= 0 && t[j] == s[r]) --j, --r;
  j = t.size() - j - 1;
  if (i + j >= s.size()) ans = max(ans, (int)(t.size() - s.size()));
  vector<int> sub_l, sub_r;
  for (i = 0, l = 0; i < t.size() && l < s.size(); ++i)
    if (t[i] == s[l]) ++l, sub_l.emplace_back(i);
  for (j = t.size() - 1, r = s.size() - 1; j >= 0 && r >= 0; --j)
    if (t[j] == s[r]) --r, sub_r.emplace_back(j);
  reverse((sub_r).begin(), (sub_r).end());
  ans = max({sub_r[0], (int)t.size() - sub_l.back() - 1, ans});
  for (int i = 1; i < sub_l.size(); ++i)
    ans = max(ans, sub_r[i] - sub_l[i - 1] - 1);
  cout << ans;
}
