def yaku(n, ns)
  if n == 2
    ns.each do |k|
      return true if k == 2
    end

    return false
  end

  for i in (0..6)
    if ns[i] > 0 && ns[i + 1] > 0 && ns[i + 2] > 0
      ns[i] -= 1
      ns[i + 1] -= 1
      ns[i + 2] -= 1

      return true if yaku(n - 3, ns)

      ns[i] += 1
      ns[i + 1] += 1
      ns[i + 2] += 1
    end
  end

  for i in (0..8)
    if ns[i] >= 3
      ns[i] -= 3

      return true if yaku(n - 3, ns)

      ns[i] += 3
    end
  end

  false
end

### main

while (line = gets)
  ns = (0..8).map{0}
  line.chomp.split("").each{|s| ns[s.to_i - 1] += 1}

  ws = []

  for i in (0..8)
    if (ns[i] < 4)
      ns0 = ns.clone
      ns0[i] += 1
      ws.push(i + 1) if yaku(14, ns0)
      ns0[i] -= 1
    end
  end

  puts (ws.length == 0) ? "0" : ws.join(" ")
end