#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t;
  cin >> s >> t;
  long long int s1 = s.size(), t1 = t.size();
  long long int left[t1];
  long long int index = 0;
  for (long long int i = 0; i < s1; i++) {
    if (s[i] == t[index]) {
      left[index] = i;
      index++;
      if (index == t1) break;
    }
  }
  long long int right[t1];
  index = t1 - 1;
  for (long long int i = s1 - 1; i >= 0; i--) {
    if (s[i] == t[index]) {
      right[index] = i;
      index--;
      if (index == -1) break;
    }
  }
  long long int ans = right[0];
  ans = max(s1 - 1 - left[t1 - 1], ans);
  for (long long int i = 1; i < t1; i++)
    ans = max(ans, right[i] - left[i - 1] - 1);
  cout << ans << "\n";
  return 0;
}
