#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    int n1, n2, i, j, mx = 0;
    string s1, s2;
    vector<int> v1, v2;
    cin >> s1 >> s2;
    n1 = s1.size();
    n2 = s2.size();
    for (i = 0, j = 0; i < n1 && j < n2; i++) {
      if (s1[i] == s2[j]) {
        v1.push_back(i);
        j++;
      }
    }
    for (i = n1 - 1, j = n2 - 1; i >= 0 && j >= 0; i--) {
      if (s1[i] == s2[j]) {
        v2.push_back(i);
        j--;
      }
    }
    reverse(v2.begin(), v2.end());
    mx = max(mx, v2[0]);
    for (i = 0; i < n2 - 1; i++) {
      mx = max(mx, v2[i + 1] - v1[i] - 1);
    }
    mx = max(mx, n1 - 1 - v1[n2 - 1]);
    cout << mx << endl;
  }
  return 0;
}
