#! /usr/bin/env ruby

S = gets.chop
T = gets.chop

@slice_patterns = []

def step(now, slice_pattern)
  slice_pattern.push(now)
  @slice_patterns.push(slice_pattern.dup)
  ((now + 1)..(S.size - 1)).to_a.each do |i|
    step(i, slice_pattern.dup)
  end
end

(0..(S.size - 1)).to_a.each do |i|
  step(i, [].dup)
end

@slice_patterns.sort! do |a, b|
  b.size <=> a.size
end

def match_substring(slice_pattern)
  t_counter = 0
  slice_pattern.each do |j|
    s_char = S[j]
    loop do
      return nil if t_counter == T.size
      t_char = T[t_counter]
      break if s_char == t_char
      t_counter += 1
    end
  end
  slice_pattern
end

def search_substring
  @slice_patterns.each do |slice_pattern|
    return slice_pattern unless match_substring(slice_pattern).nil?
  end
  []
end

result_string = search_substring.map do |i|
                  S[i]
                end

puts result_string.join