#include int xs[12]; int dfs(bool checked[12]) { int res = 0; for(int i = 0; i < 12; ++i) { if( checked[i] ) continue; if( xs[i] == 0 ) continue; checked[i] = true; for(int j = i + 1; j < 12; ++j) { if( checked[j] ) continue; if( xs[i] == xs[j] ) continue; checked[j] = true; for(int k = j + 1; k < 12; ++k) { if( checked[k] ) continue; if( xs[j] != xs[k] ) continue; checked[k] = true; int x = 100 * xs[i] + 10 * xs[j] + xs[k]; int x2 = x + dfs(checked); res = std::max(x2, res); checked[k] = false; } checked[j] = false; } checked[i] = false; } return res; } int main() { std::string str; std::cin >> str; bool checked[12] = {}; for(int i = (int)str.size(); i < 12; ++i) checked[i] = true; for(int i = 0; i < (int)str.size(); ++i) xs[i] = str[i] - '0'; printf("%d\n", dfs(checked)); return 0; }