import sys

def p(c,l,b):

 for i in l:c[i]+=[-1,1][b]

def f(c):

 if sum(c)in c:return 1

 if 5 in c:return 0

 if 4 in c:

  k=c.index(4);c[k]-=3

  if f(c):return 1

  c[k]+=3

 if 3 in c:

  k=c.index(3);c[k]-=3

  if f(c):return 1

  c[k]+=3

 for i in range(7):

  if c[i]and c[i+1]and c[i+2]:

   p(c,[i,i+1,i+2],0)

   if f(c):return 1

   p(c,[i,i+1,i+2],1)

n='123456789'

for e in sys.stdin:

 e=list(e)

 a=[i for i in n if f([(e+[i]).count(j)for j in n])]

 if a:print((*a))

 else:print((0))

import sys

def g(c,i):

 a=[0]*9

 for j in e+[i]:a[j-1]+=1

 return a

def f(c):

 if sum(c)in c:return 1

 if 5 in c:return 0

 if 4 in c:

  k=c.index(4);c[k]-=3

  if f(c):return 1

  c[k]+=3

 if 3 in c:

  k=c.index(3);c[k]-=3

  if f(c):return 1

  c[k]+=3

 for i in range(7):

  if c[i]and c[i+1]and c[i+2]:

   c[i]-=1;c[i+1]-=1;c[i+2]-=1

   if f(c):return 1

   c[i]+=1;c[i+1]+=1;c[i+2]+=1

for e in sys.stdin:

 e=list(map(int,e.strip()))

 a=[i for i in range(1,10)if f(g(e,i))]

 if a:print((*a))

 else:print((0))

import sys


def p(c, l, b):
    for i in l:
        c[i] += [-1, 1][b]


def f(c):
    if sum(c) in c:
        return 1
    if 5 in c:
        return 0
    if 4 in c:
        k = c.index(4)
        c[k] -= 3
        if f(c):
            return 1
        c[k] += 3
    if 3 in c:
        k = c.index(3)
        c[k] -= 3
        if f(c):
            return 1
        c[k] += 3
    for i in range(7):
        if c[i] and c[i + 1] and c[i + 2]:
            p(c, [i, i + 1, i + 2], 0)
            if f(c):
                return 1
            p(c, [i, i + 1, i + 2], 1)


n = "123456789"
for e in sys.stdin:
    e = list(e)
    a = [i for i in n if f([(e + [i]).count(j) for j in n])]
    if a:
        print((*a))
    else:
        print((0))

import sys


def g(c, i):
    a = [0] * 9
    for j in e + [i]:
        a[j - 1] += 1
    return a


def f(c):
    if sum(c) in c:
        return 1
    if 5 in c:
        return 0
    if 4 in c:
        k = c.index(4)
        c[k] -= 3
        if f(c):
            return 1
        c[k] += 3
    if 3 in c:
        k = c.index(3)
        c[k] -= 3
        if f(c):
            return 1
        c[k] += 3
    for i in range(7):
        if c[i] and c[i + 1] and c[i + 2]:
            c[i] -= 1
            c[i + 1] -= 1
            c[i + 2] -= 1
            if f(c):
                return 1
            c[i] += 1
            c[i + 1] += 1
            c[i + 2] += 1


for e in sys.stdin:
    e = list(map(int, e.strip()))
    a = [i for i in range(1, 10) if f(g(e, i))]
    if a:
        print((*a))
    else:
        print((0))

-def p(c, l, b): -    for i in l: -        c[i] += [-1, 1][b] +def g(c, i): +    a = [0] * 9 +    for j in e + [i]: +        a[j - 1] += 1 +    return a -            p(c, [i, i + 1, i + 2], 0) +            c[i] -= 1 +            c[i + 1] -= 1 +            c[i + 2] -= 1 -            p(c, [i, i + 1, i + 2], 1) +            c[i] += 1 +            c[i + 1] += 1 +            c[i + 2] += 1 -n = "123456789" -    e = list(e) -    a = [i for i in n if f([(e + [i]).count(j) for j in n])] +    e = list(map(int, e.strip())) +    a = [i for i in range(1, 10) if f(g(e, i))]