#include <bits/stdc++.h>
using namespace std;
int lcs(string s1, string s2){
int dp[s1.length() + 1][s2.length() + 1];
for (int i = 0; i <= s1.length(); i++)
dp[i][0] = 0;
for (int i = 0; i <= s2.length(); i++)
dp[0][i] = 0;
for (int i = 1; i <= s1.length(); i++){
for (int j = 1; j <= s2.length(); j++){
if (s1[i - 1] == s2[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
return dp[s1.length()][s2.length()];
}
int main(){
string s1, s2; cin >> s1 >> s2;
cout << lcs(s1, s2);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbGNzKHN0cmluZyBzMSwgc3RyaW5nIHMyKXsKICAgIGludCBkcFtzMS5sZW5ndGgoKSArIDFdW3MyLmxlbmd0aCgpICsgMV07CiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBzMS5sZW5ndGgoKTsgaSsrKQogICAgICAgIGRwW2ldWzBdID0gMDsKICAgIGZvciAoaW50IGkgPSAwOyBpIDw9IHMyLmxlbmd0aCgpOyBpKyspCiAgICAgICAgZHBbMF1baV0gPSAwOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gczEubGVuZ3RoKCk7IGkrKyl7CiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPD0gczIubGVuZ3RoKCk7IGorKyl7CiAgICAgICAgICAgIGlmIChzMVtpIC0gMV0gPT0gczJbaiAtIDFdKQogICAgICAgICAgICAgICAgZHBbaV1bal0gPSAxICsgZHBbaSAtIDFdW2ogLSAxXTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgZHBbaV1bal0gPSBtYXgoZHBbaV1baiAtIDFdLCBkcFtpIC0gMV1bal0pOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBkcFtzMS5sZW5ndGgoKV1bczIubGVuZ3RoKCldOwp9CgppbnQgbWFpbigpewogICAgc3RyaW5nIHMxLCBzMjsgY2luID4+IHMxID4+IHMyOwogICAgY291dCA8PCBsY3MoczEsIHMyKTsKICAgIHJldHVybiAwOyAgIAp9