#include <iostream>
#include<ctime>
#include<map>
#include<vector>
#include<queue>
using namespace std;
string a, b;
int dp[1005][1005];
int rec(int pos_a, int pos_b) {
    if(pos_a == -1 or pos_b == -1) {
        return 0;
    }
    if(dp[pos_a][pos_b] != -1) {
        return dp[pos_a][pos_b];
    }
    int result = 0;
    if(a[pos_a] == b[pos_b]) {
        result = max(result, rec(pos_a - 1, pos_b - 1) + 1);
    }
    result = max(result, rec(pos_a - 1, pos_b));
    result = max(result, rec(pos_a, pos_b - 1));
    dp[pos_a][pos_b] = result;
    return result;
}
int main()
{
    cin >> a >> b;
    for(int i = 0; i < a.size(); i++) {
        for(int j = 0; j < b.size(); j++) {
            dp[i][j] = -1;
        }
    }
    cout << rec(a.size() - 1, b.size() - 1) << endl;

    return 0;
}
