import sys sys.setrecursionlimit(10 ** 9) #再帰回数の限界を変更 ans = 0 def dfs(A,v): global ans if len(A) < 3: return for i in range(len(A)): for j in range(i+1,len(A)): for k in range(j+1,len(A)): if A[i]!=0 and A[i]!=A[j] and A[j]==A[k]: ans = max(v+A[i]*100+A[j]*11,ans) AD = [] for m in range(len(A)): if m!=i and m!=j and m!=k: AD.append(A[m]) dfs(AD,v+A[i]*100+A[j]*11) N = list(input()) L = [] for n in N: L.append(int(n)) dfs(L,0) print(ans)