from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

S = list(map(int,list(input())))
cnt = [0]*10
ans = []

for s in S:
    cnt[s] += 1

# 七対子
if cnt.count(2) == 6:
    ans.append(cnt.index(1))

def dfs1 (te):
    a = te[0]
    if te.count(a) >= 3:
        for i in range(3):
            te.remove(a)
        if len(te) == 0:
            return True
        return dfs1(te)
    elif (a+1 in te) and (a+2 in te):
        for i in range(3):
            te.remove(a+i)
        if len(te) == 0:
            return True
        return dfs1(te)
    else:
        return False


for x in range(1,10):
    if cnt[x] >= 4:
        continue
    tmpS = S + [x]
    tmpS.sort()
    # 単騎待ち
    for atama in range(1,10):
        if tmpS.count(atama) <= 1:
            continue
        nowS = tmpS[:]
        nowS.remove(atama)
        nowS.remove(atama)
        if dfs1(nowS):
            ans.append(x)

ans = list(set(ans))
ans.sort()
for a in ans:
    print(a)