import collections S = list(map(int,list(input()))) def ok3(ll): if ll[0] == ll[1] == ll[2]: return True ll.sort() if (ll[0]+2) == (ll[1]+1) and (ll[1]+1) == (ll[2]): return True return False def okall(lll): S1 = lll[:] for j in range(13): for k in range(j+1,14): if S1[j] == S1[k]: S2 = S1[:] S2.pop(j) S2.pop(k-1) for x in range(10): for y in range(x+1,11): for z in range(y+1,12): if ok3([S2[x],S2[y],S2[z]]): S3 = S2[:] S3.pop(x) S3.pop(y-1) S3.pop(z-2) for x1 in range(7): for y1 in range(x1+1,8): for z1 in range(y1+1,9): if ok3([S3[x1],S3[y1],S3[z1]]): S4 = S3[:] S4.pop(x1) S4.pop(y1-1) S4.pop(z1-2) for x2 in range(4): for y2 in range(x2+1,5): for z2 in range(y2+1,6): if ok3([S4[x2],S4[y2],S4[z2]]): S5 = S4[:] S5.pop(x2) S5.pop(y2-1) S5.pop(z2-2) if ok3([S5[0],S5[1],S5[2]]): return True if max(collections.Counter(S1).values()) == 4: continue for x in range(11): for y in range(x+1,12): if S2[x] == S2[y]: S3 = S2[:] S3.pop(x) S3.pop(y-1) for x1 in range(9): for y1 in range(x1+1,10): if S3[x1] == S3[y1]: S4 = S3[:] S4.pop(x1) S4.pop(y1-1) for x2 in range(7): for y2 in range(x2+1,8): if S4[x2] == S4[y2]: S5 = S4[:] S5.pop(x2) S5.pop(y2-1) for x3 in range(5): for y3 in range(x3+1,6): if S5[x3] == S5[y3]: S6 = S5[:] S6.pop(x3) S6.pop(y3-1) for x4 in range(3): for y4 in range(x4+1,4): if S6[x4] == S6[y4]: S7 = S6[:] S7.pop(x4) S7.pop(y4-1) if S7[0] == S7[1]: return True return False for i in range(1,10): S0 = S+[i] if max(collections.Counter(S0).values()) > 4: continue if okall(S0): print(i)