def check(l): if max(l) < 5: if l.count(2) == 7: return True for i in range(1, 10): l2 = l[:] if l2[i] >= 3: l2[i] -= 3 if check(l2): return True l2[i] += 3 for i in range(1, 8): if l2[i] and l2[i+1] and l2[i+2]: l2[i] -= 1 l2[i+1] -= 1 l2[i+2] -= 1 if check(l2): return True l2[i] += 1 l2[i+1] += 1 l2[i+2] += 1 if sum(l2) == 2 and max(l2) == 2: return True s = list(map(int,input())) for i in range(1, 10): t = s[:] t = t + [i] l = [0] * 10 for i in t: l[i] += 1 # print(l) if check(l) == True: print(i)