n = gets.chomp.chars m = n.max_by(&:to_i) i = n.size - n.reverse.index(m) - 1 j = n.find_index{|c| m.to_i > c.to_i } n[i], n[j] = n[j], n[i] if !j.nil? && j < i puts n.join