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

@pattern = (1..7).to_a.map{|i| [i,i+1,i+2]} + (1..9).map{|i| [i,i,i]}
def c(arr)
  return true if arr.size == 0
  @pattern.each do |pat|
    if (arr.size - arr.minus(pat).size) == 3
      return true if c(arr.minus(pat))
    end
  end
  return false
end

def get_pairs(arr)
  (1..9).to_a.select { |i| arr.count(i) >= 2 }
end

def keep_rule?(arr)
  return false if (1..9).any?{ |i| arr.count(i) > 4 }
  pair_nums = get_pairs(arr)
  pair_nums.each do |pn|
    rem_arr = arr.minus([pn,pn])
    return true if c(rem_arr)
  end
  return false
end

while gets do
  arr = $_.split('').map(&:to_i)
  sel = (1..9).to_a.select { |i| keep_rule?(arr+[i]) }
  puts sel.empty? ? '0' : sel.join(' ')
end