#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005, MOD = 1000000007;
pair<int, int> arr[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  string s, t;
  cin >> s >> t;
  int i = 0, j = 0, ans = -1;
  while (i < s.size() && j < t.size()) {
    if (s[i] == t[j]) arr[j++].first = i;
    i++;
  }
  int dis = s.size() - i;
  ans = max(ans, dis);
  i = s.size() - 1, j = t.size() - 1;
  while (i >= 0 && j >= 0) {
    if (s[i] == t[j]) arr[j--].second = i;
    i--;
  }
  ans = max(ans, i + 1);
  for (int i = 0; i < t.size() - 1; i++) {
    ans = max(ans, arr[i + 1].second - arr[i].first - 1);
  }
  cout << ans << "\n";
}
