N = list(input()) N = list(map(int, N)) M = len(N) M2 = 1 << M dp = [0] * M2 for i in range(M2): for a in range(M): for b in range(a + 1, M): for c in range(b + 1, M): if (i >> a) & 1: continue if (i >> b) & 1: continue if (i >> c) & 1: continue if N[a] == 0: continue if N[b] != N[c]: continue if N[a] == N[b]: continue ni = i ni |= 1 << a ni |= 1 << b ni |= 1 << c v = int(N[a]*100 + N[b]*10 + N[c]) dp[ni] = max(dp[ni], dp[i] + v) print(dp[-1])