#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int arr[t.size()];
  int q = t.size() - 1;
  int j = q;
  for (int i = s.size() - 1; i >= 0 && j >= 0; i--) {
    if (s[i] == t[j]) {
      arr[j] = i;
      j--;
    }
  }
  int arr1[t.size()];
  j = 0;
  for (int i = 0; i <= s.size() - 1; i++) {
    if (s[i] == t[j]) {
      arr1[j] = i;
      j++;
      if (j > t.size() - 1) {
        break;
      }
    }
  }
  int ans = arr[0];
  for (int i = 0; i < t.size() - 1; i++) {
    ans = max(ans, arr[i + 1] - arr1[i] - 1);
  }
  int q1 = s.size() - 1;
  ans = max(ans, q1 - arr1[q]);
  cout << ans << endl;
  return 0;
}
