import copy a = [0] * 9 s = list(map(int,input())) for i in s: a[i - 1] += 1 def seven_pairs(a): cnt = 0 for i in range(9): if a[i] == 2: cnt += 1 return cnt == 7 def can_decomp(p): cnt = 0 for i in range(9): if p[i] >= 3: cnt += 1 p[i] -= 3 if i < 7: if p[i] >= 2 and p[i+1] >= 2 and p[i+2] >= 2: cnt += 2 p[i] -= 2 p[i + 1] -= 2 p[i + 2] -= 2 elif p[i] >= 1 and p[i+1] >= 1 and p[i+2] >= 1: cnt += 1 p[i] -= 1 p[i + 1] -= 1 p[i + 2] -= 1 return cnt == 4 def check(p): for i in range(9): if p[i] >= 2: p[i] -= 2 if can_decomp(copy.deepcopy(p)): return True p[i] += 2 return False for i in range(9): if a[i] == 4: continue a[i] += 1 if seven_pairs(a): print(i + 1) elif check(copy.deepcopy(a)): print(i + 1) a[i] -= 1