#include<iostream>
#include<algorithm>
using namespace std;
string word1;
string word2;
int n1,n2;
int s[2000][2000];
void dp()
{
for (int i = 1; i <= n1; i++)
{
for (int j = 1; j <= n2; j++)
{
if (word1[i-1] == word2[j-1])
{
s[i][j] = s[i - 1][j - 1]+1;
//s[i][j]代表当word1长度为i,word2长度是j时,最长公共子串长度
//DP在从长度从小往大存
}
else
{
s[i][j] = max(s[i - 1][j], s[i][j - 1]);
}
}
}
}
int main()
{
cin>>word1>>word2;
n1=word1.length();
n2=word2.length();
dp();
cout << s[n1][n2];//
}