class Calc0039 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first end def run a = @n.split(//) a.size.times do |i| b = a[i..-1] c = b.sort.reverse if b.first != c.first j = a.rindex(c.first) a[i], a[j] = a[j], a[i] break end end a.join end end puts Calc0039.new(STDIN.readlines).run if __FILE__ == $0