def agari(r): def dfs(a,b): if a==1 and b==4: return True for i in range(1,10): if r[i]: break if a == 0 and r[i] >= 2: #頭 r[i] -= 2 if dfs(1,b): return True r[i] += 2 if b <= 3 and r[i] >= 3: #刻 r[i] -= 3 if dfs(a,b+1): return True r[i] += 3 if b <= 3 and r[i+1] and r[i+2]: #順 r[i] -= 1 r[i+1] -= 1 r[i+2] -= 1 if dfs(a,b+1): return True r[i] += 1 r[i+1] += 1 r[i+2] += 1 return False #チートイ if r.count(2) == 7: return True return dfs(0,0) r = [0]*12 for i in map(int,input()): r[i] += 1 for i in range(1,10): if r[i] == 4: continue r[i] += 1 if agari(r[:]): print(i) r[i] -= 1