let x = stdin.ReadLine () |> Seq.sortDescending |> Seq.map string |> String.concat "" let s = Set.ofSeq x if x.Length = 1 || s.Count = 1 || (s.Count = 2 && s.Contains '0') 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"