def rec(cds, hd)
  if cds.size > 0
    if cds.count(cds[0]+1) > 0 and cds.count(cds[0]+2) > 0
      cds_t = Marshal.load(Marshal.dump(cds))
      cds_t.delete_at(cds_t.index(cds[0]+2))
      cds_t.delete_at(cds_t.index(cds[0]+1))
      cds_t.shift
      return true if rec(cds_t, hd)
    end
    if cds[0] == cds[1] and hd
      cds_h = Marshal.load(Marshal.dump(cds))
      2.times{cds_h.shift}
      return true if rec(cds_h,false)
    end
    if cds[0] == cds[1] and cds[0] == cds[2]
      cds_s = Marshal.load(Marshal.dump(cds))
      3.times{cds_s.shift}
      return true if rec(cds_s, hd)
    end
  elsif cds.size == 0
    return true 
  end
end

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