s = gets
t = gets
ret = ''
[0,1].repeated_permutation(s.chars.size).sort.reverse.each do |arr|
  subchars = arr.map.with_index do |a, i|
    a == 0 ? nil : s.chars[i]
  end.compact
  next unless subchars.all? {|c| t.chars.include?(c)}
  tmp = t.chars.dup
  flg = true
  subchars.each do |c|
    if i = tmp.index(c)
      tmp = tmp[(i+1)..-1]
    else
      flg = false
      break
    end
  end
  ret = subchars.join if flg && (ret.size < subchars.size)
end

puts ret