'use strict'
const lines = require('fs').readFileSync(0, 'utf8').split('\n')
const s = lines[0]
const t = lines[1]
var dp = new Array(s.length + 1).fill("");

for (let i=0;i < s.length;i++) {
  const temp = i
  const jtemp = 0
  for (let j=0;j < t.length;j++) {
    if (s.charAt(temp) == t.charAt(j)) {
      dp[i] = dp[i] + t.charAt(j)
      temp++
      jtemp = j
    }

    if (j == t.length - 1 && temp < s.length) {
      temp++
      j = jtemp
    }
  }
}
var max = ""
for (let i=0;i < dp.length;i++) {
  if (dp[i].length > max.length) max = dp[i]
}
console.log(max)