def f(s,n): r=n for i in{*s}: p,q=s.split(i,1) for j in s: if'0'1:r=max(r,f(p+q.replace(j,'',2),n+int(i+j+j))) return r print(f(input(),0))