#include <bits/stdc++.h>
using namespace std;
long long int const mod = 1e9 + 7;
long long int const inf = 1e18;
long long int const mxn = 2e5 + 1;
inline void file() {}
int main() {
  file();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    string s, s1;
    cin >> s >> s1;
    long long int n = s.size();
    long long int m = s1.size();
    long long int dp[m], dp1[m];
    long long int j = 0;
    for (long long int i = 0; i < m; i++) {
      while (j < n && s[j] != s1[i]) {
        j++;
      }
      dp[i] = j;
      j++;
    }
    j = n - 1;
    for (long long int i = m - 1; i >= 0; i--) {
      while (j >= 0 && s[j] != s1[i]) {
        j--;
      }
      dp1[i] = j;
      j--;
    }
    long long int ans = max(dp1[0], n - 1 - dp[m - 1]);
    for (long long int i = 0; i < m - 1; i++) {
      ans = max(ans, dp1[i + 1] - dp[i] - 1);
    }
    cout << ans << "\n";
  }
}
