s1 = input()
s2 = input()
if not s1 or not s2:
	print("-1")
m = len(s1)
n = len(s2)
record = [["" for i in range(n+1)] for j in range(m+1)]
for i in range(1, m+1):
	for j in range(1, n+1):
		if s1[i-1] == s2[j-1]:
			record[i][j] = record[i-1][j-1] + s1[i-1]
		else:
			if len(record[i-1][j]) > len(record[i][j-1]):
				record[i][j] = record[i-1][j]
			else:
				record[i][j] = record[i][j-1]
if record[m][n] != "":
	print(record[m][n])
else:
	print("-1")