#include <bits/stdc++.h>
using namespace std;
string s1, s2;
vector<int> v1, v2;
int ans;
int main() {
  cin >> s1 >> s2;
  v1.push_back(-1);
  v2.push_back(s1.size());
  int l = 0, r = s2.size() - 1;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] == s2[l]) {
      v1.push_back(i);
      l++;
      if (l >= s2.size()) break;
    }
  }
  for (int i = s1.size(); i >= 0; i--) {
    if (s1[i] == s2[r]) {
      v2.push_back(i);
      r--;
      if (r <= -1) break;
    }
  }
  v1.push_back(s1.size());
  v2.push_back(-1);
  for (int i = 0; i < v1.size() - 1; i++) {
    ans = max(ans, v2[v1.size() - 2 - i] - v1[i] - 1);
  }
  printf("%d", ans);
}
