#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)

int n;
vector<int> s;

int cww(int a, int b, int c) {
    if (a != 0 && a != b && b == c) {
        return 100 * a + 10 * b + c;
    }
    return -1;
}

int dfs(vector<bool> used) {
    int ret = 0;
    rep(i, n) {
        rep2(j, i + 1, n) {
            rep2(k, j + 1, n) {
                if (used[i] || used[j] || used[k]) continue;
                int x = cww(s[i], s[j], s[k]);
                if (x != -1) {
                    vector<bool> nxused = used;
                    nxused[i] = nxused[j] = nxused[k] = true;
                    ret = max(ret, dfs(nxused) + x);
                }
            }
        }
    }
    return ret;
}

int main() {
    string tmp;
    cin >> tmp;
    n = tmp.size();
    s.resize(n);
    rep(i, n) {
        s[i] = tmp[i] - '0';
    }

    cout << dfs(vector<bool>(n)) << endl;
}