#include <bits/stdc++.h>
using namespace std;
void update(vector<long long> &mark, string &s, string &t, long long i,
            long long j, long long n, long long m, long long &last) {
  long long j1 = n - 1;
  while (j1 > j) {
    if (s[j1] == t[last]) {
      last--;
      mark[j1] = 1;
    }
    j1--;
  }
}
bool solve(string &s, string &t, long long n, long long m, long long mid) {
  long long i = 0, j = mid - 1, st = 0;
  vector<long long> mark(n);
  long long last = m - 1;
  update(mark, s, t, i, j, n, m, last);
  if (last == -1) {
    return true;
  }
  while (j < n) {
    i++;
    j++;
    if (j >= n) {
      break;
    }
    if (mark[j] == 1) {
      mark[j] = 0;
      last++;
    }
    if (s[i - 1] == t[st]) {
      st++;
      mark[i] = 1;
    }
    if (st > last) {
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s, t;
  cin >> s >> t;
  long long n = s.length(), m = t.length();
  long long low = 0, high = n, ans = 0, st = 0;
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (solve(s, t, n, m, mid)) {
      ans = max(ans, mid);
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << ans;
  return 0;
}
