#include <bits/stdc++.h>
#define int long long
#define el '\n'
#define oo LLONG_MAX >> 2
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
#define pep_Guardiola                                                          \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

signed main() {
  pep_Guardiola

      string s,
      t;
  cin >> s >> t;
  if (s.size() > t.size())
    swap(s, t);
  int n = s.size(), m = t.size();
  vector<vector<int>> nxt(m + 1, vector<int>(26, oo));
  nxt[m - 1][t[m - 1] - 'a'] = m - 1;
  for (int i = m - 1; i >= 0; i--)
    nxt[i] = nxt[i + 1], nxt[i][t[i] - 'a'] = i + 1;
  vector<int> dp(n + 2, oo);
  dp[0] = 0;
  for (int i = 1; i <= n; i++)
    for (int len = i; len >= 1; len--)
      if (dp[len - 1] != oo)
        dp[len] = min(dp[len], nxt[dp[len - 1]][s[i - 1] - 'a']);
  int ans = 0;
  for (int len = 0; len <= n; len++)
    if (dp[len] != oo)
      ans = len;
  cout << ans;
}