X = [0] * 9 for a in input(): X[int(a) - 1] += 1 def check_tempai(Y): RE = [] for i in range(9): if Y[i] < 4 and check([a + 1 if i == j else a for j, a in enumerate(Y)]): RE.append(i + 1) return RE def check(Y): for i in range(9): if Y[i] >= 2 and check_no_head([a - 2 if i == j else a for j, a in enumerate(Y)]): return 1 if Y.count(2) == 7: return 1 return 0 def check_no_head(Y): for i in range(9): if Y[i] >= 3: Y[i] -= 3 if Y[i]: if i < 7 and Y[i+1] >= Y[i] and Y[i+2] >= Y[i]: Y[i+1] -= Y[i] Y[i+2] -= Y[i] Y[i] = 0 else: return 0 return 1 print("\n".join(map(str, check_tempai(X))))