function main(input) { let X = getStrings(input, ""); X.sortByIntegerD(); let XX = X.join(""); let ans = ""; if(X.length == 2) { ans = X[1] + X[0]; } else { for(let i=X.length-1; i>0; i--) { if(X[i-1] != X[i]) { let n = X[i-1]; X[i-1] = X[i]; X[i] = n; ans = X.join(""); break; } } } if(ans == "" || ans[0] == '0' || ans == XX) { console.log(-1); } else { console.log(ans); } } //-- functions ------------------------------------ function getIntegers(lines, sep) { if(sep === undefined) { return lines.map(function(e) { return Number(e); }); } else { return lines.shift().split(sep).map(function(e) { return Number(e); }); } } function getStrings(lines, sep=" ") { return lines.shift().split(sep); } function twoDimenArrayByValue(h, w, value) { const list = new Array(h); for(let i=0; i 1) { let x = Math.floor((r + l) / 2); this[x] > V ? r = x : l = x; } return r; }; Array.prototype.lessThen = function(V, l=0, r=this.length) { l--; while(r - l > 1) { let x = Math.floor((r + l) / 2); this[x] >= V ? r = x : l = x; } return r; }; Array.prototype.orHigher = function(V, l, r) { return this.length - this.lessThen(V, l, r); }; Array.prototype.greaterThan = function(V, l, r) { return this.length - this.orLess(V, l, r); }; Array.prototype.deepCopy = function(list) { let retList = []; for(let i=0; i