S = list(map(int,input())) def solve(x): nums = [0]*10 for s in S+[x]: nums[s] += 1 if max(nums) > 4: return False two = 0 for i in nums: two += i == 2 if two == 7: return True for b in range(1<<10): nnums = nums[:] for i in range(10): if b >> i & 1: nnums[i] -= 3 if min(nnums) < 0: continue record = nnums[:] for i in range(10): nnums = record[:] if nnums[i] < 2: continue nnums[i] -= 2 for i in range(8): while nnums[i]: if nnums[i]*nnums[i+1]*nnums[i+2]: nnums[i] -= 1 nnums[i+1] -= 1 nnums[i+2] -= 1 else: break if sum(nnums) == 0 and max(nnums) == 0: return True return False for i in range(1,10): if solve(i): print(i)