// Arup Guha
// 2/23/2019
// Illustration of Memoization for Longest Common Subsequence Problem

import java.util.*;

public class lcs {
	
	public static char[] s1;
	public static char[] s2;
	public static int[][] memo;
	
	public static void main(String[] args) {

		// Get two strings from standard input.	
		Scanner stdin = new Scanner(System.in);
		s1 = stdin.next().toCharArray();
		s2 = stdin.next().toCharArray();
		
		// Set up memo table.
		memo = new int[s1.length][s2.length];
		for (int i=0; i<s1.length; i++) Arrays.fill(memo[i], -1);
		
		// Find LCS.
		System.out.println(solve(s1.length-1, s2.length-1));
	}
	
	// Returns the LCS of s1[0..i] and s2[0..j].
	public static int solve(int i, int j) {
		
		// Empty string, so answer is 0.
		if (i==-1 || j==-1) return 0;
		
		// We did this before, very important for memoization technique; avoid recursion.
		if (memo[i][j] != -1) return memo[i][j];
		
		// Greedy step - if we can, match last characters.
		// Don't forget to store before returning!!!
		if (s1[i] == s2[j]) return memo[i][j] = 1 + solve(i-1, j-1);
		
		// Otherwise, strip last character separately from both and return better of the two.
		// Don't forget to store before returning!!!
		return memo[i][j] = Math.max(solve(i-1,j), solve(i,j-1));
	}
	
	

}
