#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() template inline bool chmax(A &a, B b) { if (a inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; } typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pll; typedef pair P; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; string n; int dfs(vector v) { int res; if (v.size() == 4) { res = 0; bool done[13] = {}; REP(i, 4) { bool ok = false; for (int j = n.size() - 1; j >= 2; j--) if (!done[j] && n[j] == v[i]) { for (int k = j - 1; k >= 1; k--) if (!done[k] && n[k] == v[i]) { int ma = -1, mapos; REP(l, k) if (n[l] != 0 && n[l] != v[i] && !done[l] && chmax(ma, n[l])) mapos = l; res += n[mapos] * 100 + n[k] * 10 + n[j]; done[mapos] = done[j] = done[k] = true; ok = true; j = k = 0; } } if (!ok) break; } } else { res = 0; v.push_back(0); REP(i, 10) { v[v.size() - 1] = i; chmax(res, dfs(v)); } } return res; } int main() { cin >> n; REP(i, n.size()) n[i] -= '0'; cout << dfs(vector()) << endl; return 0; }