#include<stdio.h>
#include<string.h>
void LCSLength(int m,int n,char *x,char *y,int c[502][502]);
int main(){
char a[1002],b[1002];
while(scanf("%s%s",a,b)!=EOF){
int m=strlen(a);
int n=strlen(b);
int c[502][502];
LCSLength(m,n,a,b,c);
printf("%d\n",c[m][n]);
/*for(int i=0;i<=m;i++)
{
for(int j=0;j<=n;j++){
printf("%d ",c[i][j]);
}
putchar('\n');
}*/
}
return 0;
}
void LCSLength(int m,int n,char *x,char *y,int c[502][502]){
int i,j;
for(i=0;i<=m;i++)c[i][0]=0;
for(i=1;i<=n;i++)c[0][i]=0;
for(i=1;i<=m;i++){
for(j=1;j<=n;j++){
if(x[i-1] == y[j-1]){
c[i][j]=c[i-1][j-1]+1;
}
else if(c[i-1][j]>=c[i][j-1])
c[i][j]=c[i-1][j];
else
c[i][j]=c[i][j-1];
}
}
}