require "set" S = gets.chomp.chars st = Set.new S.size.times do |i| i.upto(S.size - 1) do |j| n = Marshal.load(Marshal.dump(S)) n[i], n[j] = n[j], n[i] st.add(n.join.to_i) end end puts st.max