open System open System.Collections.Generic [] module Cin = let read f = stdin.ReadLine() |> f let reada f = stdin.ReadLine().Split() |> Array.map f let readChars() = read string |> Seq.toArray let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString())) [] module Cout = let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput())) let print (s: string) = writer.Write s let println (s: string) = writer.WriteLine s let inline puts (s: ^a) = string s |> println let main() = let xs = readInts() |> Array.sortDescending let ng = xs |> Array.forall (fun x -> x = xs.[0]) if ng then printfn "-1" exit 0 let ys = xs |> Array.skipWhile (fun x -> x = xs.[0]) let head = xs |> Array.takeWhile (fun x -> x = xs.[0]) let same = ys |> Array.forall (fun y -> y = ys.[0]) let ys = if same then let t = head.[0] head.[0] <- ys.[0] ys.[0] <- t Array.append head ys else let yh = ys |> Array.takeWhile (fun y -> y = ys.[0]) let yt = ys |> Array.skipWhile (fun y -> y = ys.[0]) let t = yh.[0] yh.[0] <- yt.[0] yt.[0] <- t Array.concat [| head; yh; yt |] if ys.[0] = 0 then puts -1 else String.Join("", ys) |> puts () main() writer.Close()