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();

	uint[string] dp;

	string f(in string str, uint i, ulong pos, in string s1, in string s2)
	{
		if (i == s1.length) return str;

		foreach (j; pos..s2.length)
		{
			if (s1[i] == s2[j])
			{
				auto next = str ~ s1[i];
				if (i < dp.get(next, uint.max))
				{
					dp[next]  = i;
					auto r1   = f(next, i + 1, j + 1, s1, s2);
					auto r2   = f(str, i + 1, pos, s1, s2);
					return r1.length >= r2.length ? r1 : r2;
				}
				else break;
			}
		}
		return f(str, i + 1, pos, s1, s2);
	}

	auto r1 = f("", 0, 0, s, t);
	auto r2 = f("", 0, 0, t, s);
	writeln(r1.length >= r2.length ? r1 : r2);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}