#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
pair<long long, long long> tc[200050];
std::stack<long long> hasht[26];
std::stack<long long> hashs[26];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, n, m, k, q, temp, x, y;
  {
    long long count = 0;
    bool flag = 0;
    long long a[200050] = {0};
    string s, t;
    cin >> s >> t;
    long long i = 0;
    for (auto it : s) {
      hasht[it - 'a'].push(i);
      i++;
    }
    long long r = s.length() - 1;
    for (i = t.length() - 1; i >= 0; i--) {
      x = hasht[t[i] - 'a'].top();
      while (x > r) {
        hasht[t[i] - 'a'].pop();
        x = hasht[t[i] - 'a'].top();
      }
      tc[i].second = x;
      hasht[t[i] - 'a'].pop();
      r = x;
    }
    for (i = s.length() - 1; i >= 0; i--) {
      hashs[s[i] - 'a'].push(i);
    }
    long long l = 0;
    for (i = 0; i < t.length(); i++) {
      x = hashs[t[i] - 'a'].top();
      while (x < l) {
        hashs[t[i] - 'a'].pop();
        x = hashs[t[i] - 'a'].top();
      }
      tc[i].first = x;
      hashs[t[i] - 'a'].pop();
      l = x;
    }
    long long ans = 0;
    l = -1;
    for (i = 0; i < t.length(); i++) {
      ans = max(ans, tc[i].second - l - 1);
      l = tc[i].first;
    }
    ans = max(ans, (long long)s.length() - l - 1);
    cout << ans << endl;
  }
  return 0;
}
