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

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

readlines.each do |l|
  a = l.chomp.chars.map(&:to_i)
  r = (1..9).select{|i| c(a+[i])}
  puts r.empty? ? 0 : r * " "
end