#include "bits/stdc++.h" #define _CRT_SECURE_NO_WARNINGS #define rep(i,n) for(int i = 0;i < n;i++) #define REP(i,n,k) for(int i = n;i < k;i++) #define P(p) cout << (p) << endl; #define sP(p) cout << setprecision(15) << fixed << p << endl; #define vi vector #define mp(a,b) make_pair(a,b) using namespace std;typedef long long ll;typedef unsigned long long ull;int dx[] = { 1, -1 , 0 , 0};int dy[] = { 0, 0, 1, -1}; int dfs(string s){ if(s.length() < 3) return 0; int maxi = 0; rep(i,s.length()){ if(s[i] == '0')continue; REP(j,i+1,s.length()){ if(s[i] == s[j])continue; REP(k,j+1,s.length()){ if(s[j] != s[k])continue; int num = 100*(s[i]-'0') + 10*(s[j]-'0') + (s[k]-'0'); string next = ""; rep(l,s.length()){ if(l != i and l != j and l != k){ next = next + s[l]; } } maxi = max(maxi,num + dfs(next)); } } } return maxi; } void solve() { string s; cin >> s; P(dfs(s)); } int main() { solve(); return 0; }