#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
string s, t;
int a[10000005], b[10000005];
int main() {
  int i, ans = 0;
  cin >> s >> t;
  i = 0;
  a[0] = -1;
  for (int j = 0; j < s.size(); j++)
    if (s[j] == t[i]) a[++i] = j;
  i = t.size() - 1;
  for (int j = s.size() - 1; j >= 0; j--)
    if (s[j] == t[i]) b[i--] = j;
  b[t.size()] = s.size();
  for (i = 0; i <= t.size(); i++) ans = max(ans, b[i] - a[i] - 1);
  cout << ans << '\n';
  return 0;
}
