local orig = io.read("*n") local t = {} while(0 < orig) do local a = orig % 10 table.insert(t, a) orig = math.floor(orig / 10) end for j = #t, 1, -1 do local maxdig = 1 for i = 2, j do if(t[maxdig] < t[i]) then maxdig = i end end if(t[j] < t[maxdig]) then t[j], t[maxdig] = t[maxdig], t[j] break end end for i = #t, 1, -1 do io.write(t[i]) end io.write("\n")