let x = stdin.ReadLine () |> Seq.sortDescending |> Seq.map string |> String.concat "" if x.Length = 1 || (x.Length = 2 && x.[1] = '0') || Seq.forall ((=)x.[0]) x then "-1" else let mutable index = x.Length - 2 while x.[index] = x.[index+1] do index <- index - 1 (if index = 0 then "" else x.[..index-1]) + string x.[index+1] + string x.[index] + x.[index+2..] |> printfn "%s"