import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	//auto tokens = split(my_readln());
	//auto N = to!ulong(tokens[0]);
	//auto W = to!ulong(tokens[1]);

	string s = my_readln();
	string t = my_readln();

	string[][] dp;
	dp.length = 3010;
	foreach (ref e; dp) e.length = 3010;

	foreach (i; 0..s.length)
	{
		foreach (j; 0..t.length)
		{
			if (s[i] == t[j])
				dp[i+1][j+1] = dp[i+1][j+1].length >= dp[i][j].length + 1 ? dp[i+1][j+1] : dp[i][j] ~ s[i];
			dp[i+1][j+1] = dp[i+1][j+1].length >= dp[i+1][j].length ? dp[i+1][j+1] : dp[i+1][j];
			dp[i+1][j+1] = dp[i+1][j+1].length >= dp[i][j+1].length ? dp[i+1][j+1] : dp[i][j+1];
		}
	}

	writeln(dp[s.length][t.length]);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}