N = str(int(input()))[::-1] high_score = [0] def hoge(s, score): for i, c1 in enumerate(s): for j, c2 in enumerate(s[i+1:], start=i+1): if c1 != c2: continue for k, c3 in enumerate(s[j+1:], start=j+1): if c1 == c3: continue hoge(s[:i]+s[i+1:j]+s[j+1:k]+s[k+1:], score+int(c3+c2+c1)) if score > high_score[0]: high_score[0] = score hoge(N, 0) print(high_score[0])