let x = stdin.ReadLine () |> Seq.sortDescending |> Seq.map string |> String.concat "" if x.Length = 1 || Seq.forall ((=)x.[0]) x || Seq.filter ((=)'0') x |> Seq.length = x.Length - 1 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"