#include<bits/stdc++.h>
using namespace std;
int dp[5001][5001];
int main(){
string a,b;
cin>>a>>b;
for(int i=0;i<a.size();i++){
for(int j=0;j<b.size();j++){
if(a[i]==b[j]) dp[i+1][j+1]=dp[i][j]+1;
else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
}
}
cout<<dp[a.size()][b.size()];
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGRwWzUwMDFdWzUwMDFdOwoKaW50IG1haW4oKXsKCXN0cmluZyBhLGI7CgljaW4+PmE+PmI7Cglmb3IoaW50IGk9MDtpPGEuc2l6ZSgpO2krKyl7CgkJZm9yKGludCBqPTA7ajxiLnNpemUoKTtqKyspewoJCQlpZihhW2ldPT1iW2pdKSBkcFtpKzFdW2orMV09ZHBbaV1bal0rMTsKCQkJZWxzZSBkcFtpKzFdW2orMV09bWF4KGRwW2ldW2orMV0sZHBbaSsxXVtqXSk7CgkJfQoJfQoJY291dDw8ZHBbYS5zaXplKCldW2Iuc2l6ZSgpXTsKfQ==