def check(table, n)
  if n == 2
    table.find {|x| x == 2}
  else
    (1..7).each do |i|
      if table[i] > 0 and table[i + 1] > 0 and table[i + 2] > 0
        tmp = table.dup
        3.times {|j| tmp[i + j] -= 1}
        return true if check(tmp, n - 3)
      end
    end
    (1..9).each do |i|
      if table[i] >= 3
        table[i] -= 3
        return true if check(table, n - 3)
        table[i] += 3
      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, 14) ? i : nil
  end.compact
  puts result.empty? ? 0 : result.join(" ")
end
