def base10to(n, b): if (int(n/b)): return base10to(int(n/b), b) + str(n%b) return str(n%b) s = input() li = [0]*10 for i in range(len(s)): li[int(s[i])] += 1 s = li[:] num = 2**4 ans = set() for i in range(1,10): s = li[:] if s[i] == 4: continue s[i] += 1 ori = s[:] f = True for j in range(10): if s[j] != 0 and s[j] != 2: f = False if f == True: ans.add(i) continue for j in range(1,10): s = ori[:] if s[j] >= 2: s[j] -= 2 else: continue ori2 = s[:] for k in range(num): s = ori2[:] tmp = str(base10to(k,2)).zfill(4) for l in range(4): if tmp[l] == "0": for m in range(1,10): if s[m] >= 3: s[m] -= 3 break if tmp[l] == "1": for m in range(1,8): if s[m] >= 1 and s[m+1] >= 1 and s[m+2] >= 1: s[m] -= 1 s[m+1] -= 1 s[m+2] -= 1 #if tmp[l] == "2": # for m in range(3,10): # if s[m-2] >= 1 and s[m-1] >= 1 and s[m] if sum(s) == 0: ans.add(i) break ans = list(ans) ans.sort() for i in range(len(ans)): print(ans[i])