class Array
  def minus(other)
    b=self.dup
    other.each do |i|
      fl = false
      b = b.reject{ |j| i==j && !fl ? fl = true : false }
    end
    b
  end
end

@pairs=(1..7).map{|i| [i,i+1,i+2]}+(1..9).map{|i| [i,i,i]}
def c(arr)
  return false if (1..9).any?{ |i| arr.count(i) > 4 }
  return true if ((arr.size == 2)&&(arr.uniq.size == 1))
  @pairs.each do |p|
    if arr.size - arr.minus(p).size == 3
      return true if c(arr.minus(p))
    end
  end
  return false
end

while s = gets do
  arr = s.chomp.chars.map(&:to_i)
  res = (1..9).select{|i| c(arr+[i])}
  puts res.empty? ? '0' : res.join(' ')
end