#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  long long n = s.size();
  long long m = t.size();
  long long firstOccurence[m], lastOccurence[m];
  long long j = 0;
  for (long long i = 0; i < n; i++) {
    if (j < m && s[i] == t[j]) {
      firstOccurence[j] = i;
      j++;
    }
  }
  j = m - 1;
  for (long long i = n - 1; i >= 0; i--) {
    if (j >= 0 && s[i] == t[j]) {
      lastOccurence[j] = i;
      j--;
    }
  }
  long long ans = 0;
  ans = max(n - firstOccurence[m - 1] - 1, lastOccurence[0]);
  for (long long i = 0; i < m - 1; i++) {
    ans = max(ans, lastOccurence[i + 1] - firstOccurence[i] - 1);
  }
  cout << ans << endl;
}
