#include <bits/stdc++.h>
using namespace std;
bool possible(string &s, string &t, int *front_match, int *back_match,
              int val) {
  int l = 1, r = val;
  int possible = 0;
  while (r <= s.length()) {
    if ((front_match[l - 1] + back_match[r + 1]) >= t.length()) {
      possible = 1;
      break;
    }
    l++;
    r++;
  }
  return (possible);
}
int main() {
  string s, t;
  cin >> s >> t;
  int len1 = s.length(), len2 = t.length();
  int front_match[len1 + 1];
  int back_match[len1 + 2];
  front_match[0] = 0;
  back_match[len1 + 1] = 0;
  int i = 1, j = 0;
  for (; i <= len1; i++) {
    if ((j < len2) && s[i - 1] == t[j]) j++;
    front_match[i] = j;
  }
  i = len1;
  j = 0;
  for (; i > 0; i--) {
    if ((j < len2) && s[i - 1] == t[len2 - j - 1]) j++;
    back_match[i] = j;
  }
  int answer;
  int lo = 0;
  int hi = len1 - len2;
  while (lo <= hi) {
    if (lo == hi) {
      answer = lo;
      break;
    }
    if (lo == hi - 1) {
      if (possible(s, t, front_match, back_match, hi))
        answer = hi;
      else
        answer = lo;
      break;
    }
    int mid = (lo + hi) / 2;
    if (possible(s, t, front_match, back_match, mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << answer << endl;
}
