def check(table)
  result = 0
  if table.sum <= 2
    result = 1 if table.find {|x| x == 2}
  else
    (1..7).each do |i|
      tmp = table.dup
      if tmp[i].nonzero? and tmp[i + 1].nonzero? and tmp[i + 2].nonzero?
        3.times {|x| tmp[i + x] -= 1}
        result += check(tmp)
        return 1 if result.nonzero?
      end
      (1..9).each do |j|
        tmp1 = table.dup
        if tmp1[j] >= 3
          tmp1[j] -= 3
          result += check(tmp1)
          return 1 if result.nonzero?
        end
      end
    end
  end
  result
end

$<.readlines.map(&:chomp).map {|n| n.chars.map(&:to_i)}.each do |data|
  table = Array.new(10, 0)
  data.each {|i| table[i] += 1}
  result = (1..9).map do |i|
    added = table.dup
    added[i] += 1
    next if added[i] > 4
    check(added).nonzero? ? i : nil
  end.compact
  puts result.empty? ? 0 : result.join(" ")
end
