def dfs(n, used): ans = 0 for i in range(len(n)): if used[i]: continue for j in range(i + 1, len(n)): if used[j]: continue for k in range(j + 1, len(n)): if used[k]: continue if n[i] != n[j] and n[j] == n[k]: x = int(n[i] + n[j] + n[k]) used[i] = used[j] = used[k] = True ans = max(ans, x + dfs(n, used)) used[i] = used[j] = used[k] = False return ans def main(): n = input() used = [False for _ in range(len(n))] print(dfs(n, used)) if __name__ == '__main__': main()