def rec(cards, head)
  if cards.size > 0
    if cards.count(cards[0]+1) > 0 and cards.count(cards[0]+2) > 0
      cards_toitsu = Marshal.load(Marshal.dump(cards))
      cards_toitsu.delete_at(cards_toitsu.index(cards[0]+2))
      cards_toitsu.delete_at(cards_toitsu.index(cards[0]+1))
      cards_toitsu.shift
      return true if rec(cards_toitsu, head)
    end
    if cards[0] == cards[1] and head
      cards_head = Marshal.load(Marshal.dump(cards))
      2.times{cards_head.shift}
      return true if rec(cards_head,false)
    end
    if cards[0] == cards[1] and cards[0] == cards[2]
      cards_syuntsu = Marshal.load(Marshal.dump(cards))
      3.times{cards_syuntsu.shift}
      return true if rec(cards_syuntsu, head)
    end
  elsif cards.size == 0
    return true 
  end
end

while gets
  t = $_.chomp.split('').map(&:to_i).sort
  ans = []
  1.upto(9) do |i|
    tt = (Marshal.load(Marshal.dump(t)) << i).sort
    unless (tt.count(i) == 1 and tt.count([i-1,0].max) == 0 and tt.count([i+1,9].min) == 0) or tt.count(i) > 4 then
      ans << i if rec(tt,true)
    end
  end
  puts ans.empty? ? 0 : ans.join(" ")
end