def check(table)
  result = 0
  if table.sum <= 2
    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}
        return true if check(tmp)
      end
    end
    (1..9).each do |j|
      tmp1 = table.dup
      if tmp1[j] >= 3
        tmp1[j] -= 3
        return true if check(tmp1)
      end
    end
    false
  end
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) ? i : nil
  end.compact
  puts result.empty? ? 0 : result.join(" ")
end
