#include <bits/stdc++.h>
int main() {
  std::string s, t;
  std::cin >> s >> t;
  std::vector<int> dp1, dp2;
  int j = 0;
  for (int i = 0; i < t.length(); ++i) {
    while (s[j] != t[i]) {
      ++j;
    }
    dp1.push_back(j++);
  }
  j = s.length() - 1;
  for (int i = t.length() - 1; i >= 0; --i) {
    while (s[j] != t[i]) {
      --j;
    }
    dp2.push_back(j--);
  }
  std::reverse(dp2.begin(), dp2.end());
  int ans = std::max(dp1[0], int(s.length()) - dp1.back() - 1);
  ans = std::max(ans, std::max(dp2[0], int(s.length()) - dp2.back() - 1));
  for (int i = 1; i < dp1.size(); ++i) {
    ans = std::max(ans,
                   std::max(dp1[i] - dp1[i - 1] - 1, dp2[i] - dp2[i - 1] - 1));
  }
  for (int i = 0; i < int(dp2.size()) - 1; ++i) {
    ans = std::max(ans, dp2[i + 1] - dp1[i] - 1);
  }
  std::cout << ans << '\n';
  return 0;
}
