#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  while (t--) {
    long long n1, n2, i = 0, j, x, y, z, ans = 0;
    string str1, str2;
    cin >> str1 >> str2;
    n1 = str1.length();
    n2 = str2.length();
    vector<long long> rg(n2 + 1, 0);
    for (i = n1 - 1, j = n2 - 1; j >= 0; i--) {
      if (str1[i] == str2[j]) rg[j] = i, j--;
    }
    x = 0;
    for (i = 0; i < n1; i++) {
      if (x >= n2)
        y = n1 - 1;
      else {
        y = rg[x] - 1;
      }
      ans = max(ans, y - i + 1);
      if (str1[i] == str2[x]) x++;
    }
    cout << ans << "\n";
  }
  return 0;
}
