#include using namespace std; typedef long long ll; typedef vector vint; typedef pair pint; typedef vector vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define pb push_back #define mp make_pair #define fi first #define se second #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) const int MOD = 1e9 + 7; const int INF = 1e9; int main(void){ string s; cin >> s; int k = s.size(); int ret = 0; //5進数bit全探索 for (int mask = 0; mask < pow(4, k); ++mask){ int ans = 0; int tmask = mask; int bit[15]; rep(pos, k){ bit[pos] = tmask % 4; tmask /= 4; } rep(i, 4){ string tm = ""; rep(j, k){ if(bit[j] == i) tm += s[j]; } if(tm.size() == 3){ if(tm[0] != '0' && tm[1] == tm[2] && tm[0] != tm[1]){ ans += stoi(tm); } } } chmax(ret, ans); } printf("%d\n", ret); return 0; }