#include using namespace std; int cww( int a, int b, int c ){ return a != '0' and a != b and b == c; } int dfs( const string &s ){ int res = 0; for( int i = 0; i < s.size(); ++i ) for( int j = i + 1; j < s.size(); ++j ) for( int k = j + 1; k < s.size(); ++k ) if( cww( s[ i ], s[ j ], s[ k ] ) ){ string t = s; t.erase( t.begin() + k ); t.erase( t.begin() + j ); t.erase( t.begin() + i ); res = max( res, ( s[ i ] - '0' ) * 100 + ( s[ j ] - '0' ) * 10 + ( s[ k ] - '0' ) + dfs( t ) ); } return res; } signed main(){ string S; cin >> S; cout << dfs( S ) << endl; return 0; }