using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var X = Console.ReadLine(); var ans = X.OrderByDescending(z => z).ToArray(); var bef = new string(ans); for (var i = ans.Length - 2; i >= 0; i--) { Swap(ref ans[i], ref ans[i + 1]); if (ans[0] != '0' && new string(ans) != bef) { Console.WriteLine(new string(ans)); return; } } Console.WriteLine(-1); } public static void Swap(ref T one, ref T two) { var temp = one; one = two; two = temp; } } }