def check(number)
  dfs(number.dup) == 4
end

def dfs(number)
  count = 0
  for i in 0...9 do
    next if number[i] < 3
    number[i] -= 3
    count = [count, 1 + dfs(number.dup)].max
    number[i] += 3
  end
  for i in 0...9-2 do
    next if number[i] == 0 || number[i + 1] == 0 || number[i + 2] == 0
    for j in i...i+3 do
      number[j] -= 1
    end
    count = [count, 1 + dfs(number.dup)].max
    for j in i...i+3 do
      number[j] += 1
    end
  end
  count
end

while line=gets do
  number = Array.new(9, 0)
  line.chop.chars.map{|e| e.to_i - 1}.each do |e|
    number[e] += 1
  end
  answer = Array.new
  for add in 0...9 do
    next if number[add] >= 4
    number[add] += 1
    for i in 0...9 do
      next if number[i] < 2
      number[i] -= 2
      answer.push(add + 1) if check(number.dup)
      number[i] += 2
    end
    number[add] -= 1
  end
  puts answer.empty? ? 0 : answer.uniq.join(" ")
end