#include<bits/stdc++.h>
#define M 1004
using namespace std;

string a, b;
int dp[M][M];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);     cout.tie(0);

    getline(cin, a);
    getline(cin, b);
    int n = a.size();
    int m = b.size();
    a = ' ' + a;
    b = ' ' + b;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(a[i] == b[j])   dp[i][j] = dp[i - 1][j - 1] + 1;
            else    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    cout << dp[n][m];
}
