#include <bits/stdc++.h>
using namespace std;
long long power(long long, long long);
long long mpower(long long, long long);
long long leftl[1000009];
long long rightl[1000009];
string s, t;
bool check(long long n) {
  for (long long i = 0; i + n <= s.size(); i++) {
    if (i == 0) {
      if (rightl[i + n] == 0) return 1;
      continue;
    }
    if (leftl[i - 1] + 1 >= rightl[i + n]) return true;
  }
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  for (long long i = 0, j = 0; i < s.size(); i++) {
    if (j < t.size() and s[i] == t[j]) {
      leftl[i] = j;
      j++;
    } else {
      if (i > 0)
        leftl[i] = leftl[i - 1];
      else
        leftl[i] = -1;
    }
  }
  for (long long i = s.size() - 1, j = t.size() - 1; i >= 0; i--) {
    if (j >= 0 and s[i] == t[j]) {
      rightl[i] = j;
      j--;
    } else {
      if (i < s.size() - 1)
        rightl[i] = rightl[i + 1];
      else
        rightl[i] = s.size() + 1;
    }
  }
  rightl[s.size()] = t.size();
  long long l = 0, r = s.size() - 1;
  while (l < r) {
    long long mid = l + (r - l + 1) / 2;
    if (check(mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << l << endl;
  return 0;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 1) res = res * a;
    a = a * a;
    b = b / 2;
  }
  return res;
}
long long mpower(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b = b / 2;
  }
  return res;
}
