#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a-1); i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1005;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
char a[maxn],b[maxn];
int dp[maxn][maxn];
int solve(int x = -1)
{
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
if(x != -1){
char infile[10] = "0.in";
char outfile[10] = "0.out";
infile[0] = outfile[0] = '0'+x;
freopen(infile, "r", stdin);
freopen(outfile, "w", stdout);
}
scanf("%s%s", a+1, b+1);
int n = strlen(a+1);
int m = strlen(b+1);
memset(dp, 0, sizeof dp);
rep(i, 1, n+1){
rep(j, 1, m+1){
if(a[i] == b[j]) dp[i][j] = dp[i-1][j-1]+1;
else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
}
}
cout << dp[n][m] << endl;
if(x != -1){
fclose(stdin);
fclose(stdout);
}
return 0;
}
int main(){
//for(int i = 0;i < 10;i++) solve(i);
solve();
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
static int maxn = 1005;
static int logn = (int)(Math.log(maxn) / Math.log(2)) + 5;
static int inf = 0x3f3f3f3f;
static double eps = 1e-9;
static char a[] = new char[maxn];
static char b[] = new char[maxn];
static int dp[][] = new int[maxn][maxn];
public static int solve(int x) {
if (x != -1) {
String infile = "0.in";
String outfile = "0.out";
infile = "" + (char)('0' + x);
outfile = "" + (char)('0' + x);
try {
System.setIn(new FileInputStream(infile));
System.setOut(new PrintStream(outfile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Scanner sc = new Scanner(System.in);
String sa = sc.nextLine();
String sb = sc.nextLine();
int n = sa.length();
int m = sb.length();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (sa.charAt(i-1)==sb.charAt(j-1))
dp[i][j] = dp[i] [j-1] + 1;
else
dp[i][j] = Math.max(dp[i][j-1], dp[i-1][j]);
}
}
System.out.println(dp[n][m]);
if (x != -1) {
try {
System.in.close();
System.out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
public static void main(String[] args) {
solve(-1);
}
}