def f(s,n): r=n;d=set(s) for i in d: for j in d: t=i+j+j;a='' for k in s: if t and k==t[0]:t=t[1:] else:a+=k if not all((i in['0',j],t)):r=max(r,f(a,n+int(i+j+j))) return r print(f(input(),0))