#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string a, b;
  cin >> a >> b;
  long long n = a.size(), m = b.size();
  vector<long long> v(n + 2, 0);
  vector<long long> q(n + 2, 0);
  long long i = n, j = m;
  while (i >= 0) {
    if (j >= 1 && a[i - 1] == b[j - 1]) {
      v[i] = v[i + 1] + 1;
      j--;
    } else
      v[i] = v[i + 1];
    i--;
  }
  i = 1, j = 1;
  while (i <= n + 1) {
    if (j <= m && a[i - 1] == b[j - 1]) {
      q[i] = q[i - 1] + 1;
      j++;
    } else
      q[i] = q[i - 1];
    i++;
  }
  long long ans = 0;
  for (long long x = 1; x <= n; x++) {
    for (long long y = x; y <= n; y++) {
      if (q[x - 1] + v[y + 1] >= m) {
        ans = max(ans, y - x + 1);
      }
    }
  }
  cout << ans << endl;
}
