open Batteries

let () =
  let find_opt f t =
    let rec loop = function
      | [] -> None
      | x :: l -> if f x then Some x else loop l
    in
    loop t
  in

  let a = Scanf.scanf "%s\n" (fun a -> a) in
  let input_char_list = BatString.to_list a in
  let all_chars = ['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o';'p';'q';'r';'s';'t';'u';'v';'w';'x';'y';'z';] in

  let res =
    if (String.length a < 26)
    then (
      let hoge input_chars all_chars =
        let rec aux l = match l with
          | [] -> []
          | hd :: tl -> 
            (
              match (find_opt (fun x -> x = hd) input_chars) with
                Some x -> aux tl 
              | None -> [hd]
            )
        in
        aux all_chars
      in
      BatList.append input_char_list (hoge input_char_list all_chars) |> BatString.of_list
    )
    else (
      if (a = "zyxwvutsrqponmlkjihgfedcba")
      then ("-1")
      else (

        let rec loop l accum = match l with
          | hd1 :: hd2 :: tl ->
            if ((BatChar.code hd1) < (BatChar.code hd2))
            then
              loop (hd2 :: tl) (List.append accum [hd1])
            else
              let accum = List.append accum [hd1] in
              let accum = List.sort compare accum in
              let replacer = List.find (fun x -> x > hd2) accum in
              replacer :: tl
          | hd :: [] -> []
          | [] -> []
        in
        loop (List.rev input_char_list) [] |> 
        List.rev |>
        BatString.of_list
      )
    )
  in print_endline res
