Problem:
Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

1 \leq |S| \leq 26

S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.

Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.

Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.

Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx

Solution in Fortran (gfortran v4.8.4) (judge verdict: Accepted)

program name
    implicit none
    character(26):: s
    character(1):: mins
    integer(4):: ls,i,mic, ri
    integer(4),allocatable:: si(:)
    logical:: is_use(26)

    read*, s
    ls = len_trim(s)
    allocate(si(ls))

    do i=1,ls
        si(i) = ichar(s(i:i)) - ichar('a') + 1
    end do

    is_use(:) = .false.

    do i=1,ls
        is_use(si(i)) = .true.
    end do

    mic=10001
    do i=1,26
        if (.not. is_use(i))  mic=min(mic,i)
    end do

    if (mic==10001) then
        ri = 1000
        do i=ls,2,-1
            if (s(i-1:i-1) < s(i:i)) then
                ri = i
                exit
            end if
        end do

        if(ri == 1000) then
            print*, -1
            stop
        end if
        mins='z'
        do i=ri,ls
            if (s(ri-1:ri-1) >= s(i:i)) cycle
            mins = min(s(i:i),mins)
        end do
        print*, s(1:ri-2) // mins
        stop
    end if



    s(ls+1:ls+1) = char(mic+ichar('a')-1)

    print*, trim(s)


end program name