#include <bits/stdc++.h> using namespace std; typedef long long ll; int dfs(string s, int m, int sum) { int mx=sum; for (int i=0;i<s.size();i++) if (s[i]!='0'&&~m&1<<i) for (int j=i+1;j<s.size();j++) if (s[i]!=s[j]&&~m&1<<j) for (int k=j+1;k<s.size();k++) if (s[j]==s[k]&&~m&1<<k) mx=max(mx,dfs(s,m|1<<i|1<<j|1<<k,sum+stoi(""+s[i]+s[j]+s[k]))); return mx; } int main() { string s; cin>>s; cout<<dfs(s,0,0)<<endl; return 0; }