def f(s,u,c): m=c for i in range(len(s)): for j in range(i+1,len(s)): for k in range(j+1,len(s)): if s[i]!='0' and s[j]==s[k]and s[i]!=s[j]: if not(u[i]or u[j]or u[k]): u[i]=u[j]=u[k]=True;m=max(m,f(s,u,c+int(s[i]+s[j]+s[k])));u[i]=u[j]=u[k]=False return m s=input() u=[False]*len(s) print(f(s,u,0))