using System; using System.Linq; using System.Collections.Generic; namespace yukicoder { class Programs { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var list = new List(); int tn = N; while(tn > 0) { list.Add(tn % 10); tn /= 10; } list.Reverse(); for(int p = 0;p < list.Count - 1;p++) { int head = list[p]; int max = -1; int maxIndex = -1; for(int q = p + 1;q < list.Count;q++) { int ch = list[q]; if(max <= ch) { max = ch; maxIndex = q; } } if(max == -1 || max <= head) { continue; }else { list[p] = max; list[maxIndex] = head; break; } } list.Reverse(); int sum = 0; int a = 1; foreach(int i in list) { sum += a * i; a *= 10; } Console.WriteLine(sum); } } }