def tsumo?(a)
    g = Hash[*a.group_by(&:itself).map {|k, s| [k, s.size]}.flatten]
    return false if g.values.max > 4
    return g.keys.any? {|i| f1(g, i)}
end

def f1(g, i)
    return false if g[i] == 1
    h = g.dup
    h[i] -= 2
    h.delete(i) if h[i] == 0
    return f2(h)
end

def f2(g)
    return true if g.empty?
    i = g.keys.min
    if g[i] >= 3
        h = g.dup
        h[i] -= 3
        h.delete(i) if h[i] == 0
        return true if f2(h)
    end
    if g[i] && g[i+1] && g[i+2]
        h = g.dup
        h[i] -= 1
        h[i+1] -= 1
        h[i+2] -= 1
        h.delete(i) if h[i] == 0
        h.delete(i+1) if h[i+1] == 0
        h.delete(i+2) if h[i+2] == 0
        return true if f2(h)
    end
    return false
end

while l = gets
    a = l.chomp.split("").map(&:to_i)
    ans = (1..9).select {|i| tsumo?(a + [i])}
    puts ans.empty? ? '0' : ans * ' '
end

