const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const str1 = await readline();
const str2 = await readline();
let p = 0;
let maxLength = 0;
let dp = new Array(str1.length + 1)
.fill(0)
.map(() => new Array(str2.length + 1).fill(0));
for (let i = 0; i < str1.length; i++) {
for (let j = 0; j < str2.length; j++) {
if (str1[i] == str2[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
if (dp[i + 1][j + 1] > maxLength) {
maxLength = dp[i + 1][j + 1];
p = i + 1;
}
}
}
}
console.log(str1.slice(p - maxLength, p));
})();