from itertools import combinations N = list(input()) L = list(range(len(N))) ans = 0 if len(L)<3: print(0) else: for x in combinations(L,3): cnt = 0 x1 = N[x[0]]+N[x[1]]+N[x[2]] if N[x[0]]!="0" and N[x[0]]!=N[x[1]] and N[x[1]]==N[x[2]]: cnt += int(x1) ans = max(ans,cnt) L1 = [] for i in L: if i not in x: L1.append(i) if len(L1)<3: cnt = 0 continue for y in combinations(L1,3): y1 = N[y[0]]+N[y[1]]+N[y[2]] cnt1 = cnt if N[y[0]]!="0" and N[y[0]]!=N[y[1]] and N[y[1]]==N[y[2]]: cnt1 += int(y1) ans = max(ans,cnt1) L2 = [] for i in L1: if i not in y: L2.append(i) if len(L2)<3: continue for z in combinations(L2,3): z1 = N[z[0]]+N[z[1]]+N[z[2]] cnt2 = cnt1 if N[z[0]]!="0" and N[z[0]]!=N[z[1]] and N[z[1]]==N[z[2]]: cnt2 += int(z1) ans = max(ans,cnt2) L3 = [] for i in L2: if i not in z: L3.append(i) if len(L3)<3: continue for w in combinations(L3,3): w1 = N[w[0]]!="0" and N[w[0]]+N[w[1]]+N[w[2]] cnt3 = cnt2 if N[w[0]]!=N[w[1]] and N[w[1]]==N[w[2]]: cnt3 += int(w1) ans = max(ans,cnt3) print(ans)