using System; namespace No._39 { class Program { static void Main(string[] args) { string number = Console.ReadLine(); int result, max = 0; for (int i = 0; i < number.Length - 1; i++) { result = int.Parse(number.Substring(0, i) + MaxNumber(number.Substring(i))); if (max < result) max = result; } Console.WriteLine(max); } static string MaxNumber(string number) { int pos = 0, max = int.Parse(number[0].ToString()); string result; for (int i = 1; i < number.Length; i++) if (max <= int.Parse(number[i].ToString())) { max = int.Parse(number[i].ToString()); pos = i; } result = number[pos].ToString(); for (int i = 1; i < number.Length; i++) if (i == pos) result += number[0].ToString(); else result += number[i].ToString(); return result; } } }