#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
bitset<N> bs;
int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  vector<int> lpos(t.size());
  for (int i = t.length() - 1; i >= 0; i--) {
    int pos = s.length() - 1;
    if (i != t.length() - 1) pos = lpos[i + 1] - 1;
    while (s[pos] != t[i]) pos--;
    lpos[i] = pos;
  }
  int pos = 0;
  int n = s.length();
  for (int i = 0; i < s.length(); i++) {
    if (pos < t.length())
      ans = max(ans, lpos[pos] - i);
    else
      ans = max(ans, n - i);
    if (pos < t.length() && s[i] == t[pos]) pos++;
  }
  cout << ans;
}
