#include <bits/stdc++.h>
using namespace std;
const long double pi = acos((long double)-1.0);
const double eps = (double)1e-9;
const int inf = (int)1e9 + 7;
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto i : v) os << i << ' ';
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
int main(void) {
  vector<int> first;
  vector<int> last;
  string second, t;
  cin >> second >> t;
  int n = second.size(), m = t.size();
  for (int i = 0, j = 0; i < n and j < m and first.size() < m; i++) {
    if (second[i] == t[j]) {
      first.push_back(i);
      j++;
    }
  }
  for (int i = n - 1, j = m - 1; i >= 0 and j >= 0 and last.size() < m; i--) {
    if (second[i] == t[j]) {
      last.push_back(i);
      j--;
    }
  }
  reverse(last.begin(), last.end());
  int ans = max({n - 1 - first[m - 1], last[0], first[0], n - 1 - last[m - 1]});
  for (int i = 0; i < m - 1; i++) {
    ans = max(ans, last[i + 1] - first[i] - 1);
  }
  cout << ans;
  return 0;
}
