S = gets.chomp.chars
T = gets.chomp.chars

def calc(s, t)
  return '' if s.empty? || t.empty?

  s0, *s1 = s
  t0, *t1 = t

  return s0 + calc(s1, t1) if s0 == t0

  s2 = calc(s1, t)
  t2 = calc(s, t1)

  s2.size > t2.size ? s2 : t2
end

print calc(S, T)
