def judge(tile): cnt = 0 for i in range(0, 9): if tile[i] > 4: return False for i in range(0, 9): if tile[i] == 2: cnt += 1 if cnt == 7: return True pair = [] for i in range(0, 9): if tile[i] >= 2: pair.append(i) queue = [] for i in range(0, len(pair)): newtile = [] for j in range(0, 9): if j == pair[i]: newtile.append(tile[j]-2) else: newtile.append(tile[j]) queue.append(newtile) while(queue != []): now = queue.pop(0) flag = True for i in range(0, 9): if now[i] != 0: flag = False break if flag: return True for i in range(0, 9): if now[i] >= 3: nexttile = [] for j in range(0, 9): if j == i: nexttile.append(now[j]-3) else: nexttile.append(now[j]) if now != nexttile and nexttile not in queue: queue.append(nexttile) if i < 7: if now[i] >= 1 and now[i+1] >= 1 and now[i+2] >= 1: nexttile = [] for j in range(0, 9): if i <= j and j <= i+2: nexttile.append(now[j]-1) else: nexttile.append(now[j]) if now != nexttile and nexttile not in queue: queue.append(nexttile) return False S = raw_input() tiles = [] for i in range(0, 9): tiles.append(0) for i in range(0, 13): n = int(S[i]) tiles[n-1] += 1 for i in range(0, 9): newtiles = [] for j in range(0, 9): if i == j: newtiles.append(tiles[j]+1) else: newtiles.append(tiles[j]) if judge(newtiles): print i+1