// 1
// 2
// 3
// 4
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
// Í.Î.Ï.
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
const int N = (int)1e3;
char s[N + 1], t[N + 1];
int sn, tn;
short f[N + 2][N + 2];
inline int calc( int i, int j )
{
if (!i || !j)
return 0;
if (f[i][j] != -1)
return f[i][j];
if (s[i - 1] == t[j - 1])
f[i][j] = calc(i - 1, j - 1) + 1;
else
f[i][j] = max(calc(i - 1, j), calc(i, j - 1));
return f[i][j];
}
void solve()
{
memset(f, -1, sizeof(f));
printf("%d\n", calc(sn, tn));
}
int main()
{
gets(s);
gets(t);
sn = strlen(s);
tn = strlen(t);
solve();
return 0;
}