#include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cstring>
using namespace std;
inline int max(int a,int b)
{
return a>b?a:b;
}
int c[1005][1005];
int main()
{
int l1,l2;
string s1,s2;
while(cin>>s1>>s2)
{
memset(c,0,sizeof(c));
l1=s1.length();
l2=s2.length();
for(int i=1;i<=l1;i++)
for(int j=1;j<=l2;j++)
{
if(s1[i-1]==s2[j-1])
c[i][j]=c[i-1][j-1]+1;
else
{
c[i][j]=max(c[i-1][j],c[i][j-1]);
}
}
cout<<c[l1][l2]<<endl;
}
return 0;
}