s=gets.chomp.split("").map{|e| e.to_i}.sort.reverse s2=s.size-1 ans=-1 ok=false s2.downto(1){|i| j=i-1 if s[i]!=s[j] then s[i],s[j]=s[j],s[i] ok=true break end } ans=s.join("") if ok && s[0]!=0 puts ans