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 (Python):
a=input().strip()
if len(a)<26:
  for i in range(97, 97+26):
    if chr(i) not in list(a):
      print(a+chr(i))
      break
else:
  f=False
  for i in range(26):
    t0=a[25-i:]
    ts=list(t0)
    ts.sort(reverse=True)
    t1="".join(ts)
    
    if t0 != t1 :
      for j in range(len(ts)):
        if ts[len(ts)-1-j]==t0[0]:
          print(a[:25-i]+ts[len(ts)-1-j-1])
          f=True
          break
    if f == True:
      break
  else:
    print(-1)

Solution (Python):
S = input()
cnt = [S.count(chr(ord('a')+i)) for i in range(26)]
if sum(cnt) == 26:
    pos = 0
    for j in range(25, 0, -1):
        if S[j] > S[j-1]:
            pos = j
            break
    if pos == 0:
        print(-1)
    else:
        a = S[pos:26]
        for x in a[::-1]:
            if S[pos-1] < x:
                T = S[:pos-1] + x
                print(T)
                break


else:
    for j in range(26):
        if cnt[j] == 0:
            S += chr(ord('a')+j)
            print(S)
            break

Solution (Python):
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(1, 26):
        idx = 25 - i
        if max(S[idx:]) != S[idx]:
            mc = min([c for c in S[(idx+1):] if c > S[idx]])
            ret = S[:idx] + mc
            break
    if ret is None:
        print(-1)
    else:
        print(ret)

Solution (Python):
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(1, 26):
        idx = 25 - i
        if max(S[idx:]) != S[idx]:
            mc = min([c for c in S[(idx+1):] if c > S[idx]])
            ret = S[:idx] + mc
            break
    if ret is None:
        print(-1)
    else:
        print(ret)

Solution (Python):
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(26):
        if max(S[25-i:]) != S[25-i]:
            mc = 'z'
            for c in S[25-i:]:
                if c > S[25-i]:
                    mc = min(c, mc)
            ret = S[:25-i] + mc
            break
            
    if ret is None:
        print(-1)
    else:
        print(ret)

Solution (Python):
S = input()

if len(S) < 26:
    for c in 'abcdefghijklmnopqrstuvwxyz':
        if c not in S:
            print(S + c)
            break
else:
    cs = {S[-1]}
    for i in range(25)[::-1]:
        if S[i] < S[i + 1]:
            for c in sorted(list(cs)):
                if c > S[i]:
                    print(S[:i] + c)
                    break
            break
        else:
            cs.add(S[i])
    else:
        print('-1')

Solution (Python):
s = input()
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
ns = [ord(c) - 97 for c in s]
ns_ = [i for i in range(26) if i not in ns]
if len(ns) == 26:
    ms = [0]
    while True:
        ms.append(ns.pop())
        if ms[-1] < ms[-2]:
            min_m = 27
            for m in ms:
                if m < min_m and m > ms[-1]:
                    min_m = m
            ns.append(min_m)
            break
else:
    ns.append(min(ns_))
cs = [chr(n + 97) for n in ns]
print(''.join(cs))

Solution (Python):
def solve(s):
  cnt="abcdefghijklmnopqrstuvwxyz"
  res=[0 for x in range(26)]
  for i in range(len(s)):
    a=cnt.index(s[i])
    res[a]+=1
  for i in range(26):
    if res[i]==0:
      return s+cnt[i]

def solve26(ss):
  s=ss
  cnt="abcdefghijklmnopqrstuvwxyz"
  pos=s[-1]
  res=cnt.index(pos)+1
  s=s[:-1]
  for i in range(res,26):
    jud=True
    pos=cnt[i]
    for j in range(len(s)):
      if s[j]==cnt[i]:
        jud=False
        break
    if jud:
      return s+pos
  return solve26(s)

S=input()
if len(S)==26 and S=='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(S)==26:
  S=solve26(S)
  print(S)
else:
  S=solve(S)
  print(S)

Solution (Python):
from string import ascii_lowercase

S = raw_input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print -1
elif len(S) == 26:
    S = [ascii_lowercase.index(s) for s in S]
    while True:
        S[-1] += 1
        if S[-1] >= 26:
            S.pop()
        elif len(set(S)) == len(S):
            break
    print ''.join([ascii_lowercase[i] for i in S])
else:
    for a in ascii_lowercase:
        if a not in S:
            print S + a
            break

Solution (Python):
import sys

alphabets = "abcdefghijklmnopqrstuvwxyz"
S = input()
mp = {}

for s in S:
    if s in mp.keys():
        mp[s] = mp[s] + 1
    else:
        mp[s] = 1

def idx(c):
    if len(c) != 1:
        print("error")
        return None 
    for i, e in enumerate(alphabets):
        if c == e:
            return i
    print("error")
    return None 


unused = []
for a in alphabets:
    if a not in mp.keys():
        unused.append(a)
        
if len(unused) > 0:
    print(S + unused[0])
    sys.exit(0)


pos = len(S) - 1
while True:
    if pos == 0:
        print(-1)
        sys.exit()
    x = S[pos-1]
    y = S[pos]
    if idx(x) < idx(y):
        
        minc = 'z'
        unused.append(y)
        for c in unused:
            if idx(minc) > idx(c) and idx(c) > idx(x):
                minc = c
        print(S[:pos-1] + minc)
        sys.exit()
    else:
        unused.append(y)

    
    pos = pos - 1

"""
abcdefghijklmnopqrstuvwzyx
abcdefghijklmnopqrstuvzyxw
azyxwvutsrqponmlkjihgfedcb
"""

Solution (Python):
s = input()
t = set(map(chr, range(ord('a'), ord('z')+1))) - set(s)
if t:
    print(s + min(t))
else:
    u = {s[-1]}
    for i in range(len(s)-1)[::-1]:
        x = [c for c in u if s[i]<c]
        if x:
            print(s[:i] + min(x))
            break
        u.add(s[i])
    else:
        print(-1)

Solution (Python):
if __name__ == '__main__':
    s = input()
    alpha = list([1 for i in range(26)])
    if len(s) != 26:
        for i in range(len(s)):
            if(alpha[ord(s[i])-97] == 0):
                print("-1")
                exit()
            alpha[ord(s[i])-97] = 0
        for i in range(len(alpha)):
            if alpha[i]==1:
                print(str(s)+chr(i+97))
                exit()
        print("-1")
        exit()
    else:
        max = ord(s[-1])-97
        alpha[ord(s[-1])-97] = 0
        
        for i in reversed(range(len(s)-1)):
            if ord(s[i])-97 <  max:
                for j in range(len(alpha)):
                    if alpha[j] == 0 and ord(s[i])-97<j:
                        print(s[:i]+chr(j+97))
                        exit()
            else:
                max = ord(s[i])-97
            alpha[ord(s[i])-97] = 0
        print("-1")
        exit()

Solution (Python):
import string


def main():
    """
    abcdefghijklmnopqrstuvwxyz
    zyxwvutsrqponmlkjihgfedcba
    """
    S = input()

    az = string.ascii_lowercase
    za = az[::-1]
    if len(S) < len(az):
        
        s_s = set(S)
        s_az = set(az)
        a = sorted(list(s_az - s_s))[0]

        
        ans = S + a
        print(ans)
        return

    editorial(S)

def editorial(S):
    for i in range(1, 26)[::-1]:
        if S[i-1] > S[i]:
            continue

        
        
        suffix = S[i:]
        p_1 = S[i-1]
        for q in sorted(suffix):
            if q > p_1:
                ans = S[:i-1] + q
                print(ans)
                return
    print(-1)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()

def itoc(i): return chr(ord('a') + i)
def ctoi(c): return ord(c) - ord('a')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
if len(S) == 26:
    i = 25
    while i > 0:
        if S[i-1] > S[i]:
            i -= 1
        else:
            ans = S[:i-1]
            for ci in range(ctoi(S[i-1])+1, 27):
                if itoc(ci) in ans: continue
                ans += itoc(ci)
                print(ans)
                exit()
else:
    for i in range(26):
        c = itoc(i)
        if c in S: continue
        print(S + c)
        break

Solution (Python):
S = input()

def solve():
    alpha = [c for c in 'abcdefghijklmnopqrstuvwxyz']
    if len(S) < 26:
        for S_i in S:
            alpha.remove(S_i)
        print(S + alpha[0])
        return
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        return
    last_alpha = ""
    post_fix = ""
    latest = -1
    post_fix_index = 25
    for S_i in S[::-1]:
        if last_alpha == "" or S_i > last_alpha:
            last_alpha = S_i
            post_fix = S_i + post_fix
            post_fix_index -= 1
            if latest == -1:
                latest = S_i
        else:
            alpha_post_fix = sorted([c for c in post_fix])
            for c in alpha_post_fix:
                if S[post_fix_index] < c:
                    print(S[:post_fix_index] + c)
                    return


solve()

Solution (Python):
s = input()
x = "abcdefghijklmnopqrstuvwxyz"
if len(s)!=26:
	for i in x:
		 if i not in s:
		 	letter = i
		 	break
	print(s+letter)
elif s=="zyxwvutsrqponmlkjihgfedcba":
	print(-1)
else:
	for i in range(24,-1,-1):
		if x.find(s[i])<x.find(s[i+1]):
			s,s2,y = s[:i],s[i:],s[i]
			break
	s3 = []
	for i in s2: s3.append(i)
	s3.sort()
	letter = s3[s3.index(y)+1]
	print(s+letter)

Solution (Python):









def determine_next_word(given_word: str) -> str:
    while given_word:
        pi = ascii_lowercase.index(given_word[-1])
        given_word = given_word[:-1]

        for character in ascii_lowercase[pi + 1:]:
            if character not in given_word:
                return given_word + character


if __name__ == '__main__':
    from string import ascii_lowercase
    s = input()

    if len(s) < 26:
        result = [s + character for character in ascii_lowercase if character not in s][0]
        print(result)
    elif s == ascii_lowercase[::-1]:
        print(-1)
    else:
        print(determine_next_word(given_word=s))

Solution (Python):
def solve(S):
    chars = [chr(c) for c in range(ord("a"), ord("z") + 1)]
    cs = dict((c, S.count(c)) for c in chars)
    l = len(S) 
    if l < len(chars):
        return S + sorted(c for c, n in cs.items() if n == 0)[0]
    for i in range(2, l + 1):
        sl = S[:l - i]
        sc = S[l - i]
        sr = S[l - i + 1:]
        msrs = [c for c in sr if c > sc]
        if msrs:
            return sl + sorted(msrs)[0]
    return -1

S = input()
print(solve(S))

Solution (Python):
S = input()
C = [chr(97+i) for i in range(26)]

if len(S) != 26:
    for c in C:
        if c not in S:
            print(S + c)
            break
else:
    S = list(S)
    for i in range(25, -1, -1):
        if S[i:] != sorted(S[i:], reverse=True):
            Z = sorted(list(filter(lambda x: x > S[i], S[i:])))
            print("".join(S[:i]) + Z[0])
            break
    else:
        print(-1)

Solution (Python):
s = input()
n = len(s)

d = dict()
d['a'] = 1
d['b'] = 2
d['c'] = 3
d['d'] = 4
d['e'] = 5
d['f'] = 6
d['g'] = 7
d['h'] = 8
d['i'] = 9
d['j'] = 10
d['k'] = 11
d['l'] = 12
d['m'] = 13
d['n'] = 14
d['o'] = 15
d['p'] = 16
d['q'] = 17
d['r'] = 18
d['s'] = 19
d['t'] = 20
d['u'] = 21
d['v'] = 22
d['w'] = 23
d['x'] = 24
d['y'] = 25
d['z'] = 26

e = dict()
e[1] = 'a'
e[2] = 'b'
e[3] = 'c'
e[4] = 'd'
e[5] = 'e'
e[6] = 'f'
e[7] = 'g'
e[8] = 'h'
e[9] = 'i'
e[10] = 'j'
e[11] = 'k'
e[12] = 'l'
e[13] = 'm'
e[14] = 'n'
e[15] = 'o'
e[16] = 'p'
e[17] = 'q'
e[18] = 'r'
e[19] = 's'
e[20] = 't'
e[21] = 'u'
e[22] = 'v'
e[23] = 'w'
e[24] = 'x'
e[25] = 'y'
e[26] = 'z'

appear = [0 for i in range(27)]
string = [0]
for i in range(n):
	string.append(d[s[i]])
	appear[d[s[i]]] += 1

exist = 0
for i in range(1,27):
	if appear[i] == 0:
		exist = i
		break

if exist != 0: 
	string.append(exist)
	for k in range(1,n+2):
		if k != n+1:
			print(e[string[k]],end='')
		else:
			print(e[string[k]])
else:
	if s == 'zyxwvutsrqponmlkjihgfedcba':
		print('-1')
	else:
		bunki = 26
		i = 26
		while i > 1:
			if string[i-1] > string[i]:
				bunki = i-1
				i += -1
			else:
				break
		memo = []
		for k in range(bunki,27):
			memo.append(string[k])
		memo.sort()
		t = [string[bunki-1]]
		for k in range(len(memo)):
			if t[0] < memo[k]:
				okikae = memo[k]
				break
		string[bunki-1] = okikae
		for h in range(1,bunki):
			if h!= bunki-1:
				print(e[string[h]],end='')
			else:
				print(e[string[h]])

Solution (Python):
inp = input()
inp_len = len(inp)
chars = map(ord,list(inp))
dic = {}
an = ""
if inp == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
if inp_len == 26:
    for i in range(25):
        if ord(inp[-1 - i]) > ord(inp[-2 - i]):
            an = inp[:-2-i]
            ls = inp[-2-i]
            for char in map(ord,list(inp[-1-i:])):
                dic[char] = "exist"
            break
    for j in range(26):
        if  97 + j in dic and 97+ j  >  ord(ls):
            an =  an + chr(97+j)
            break
else:
    for char in chars:
        dic[char] = "exist"
    for i in range(26):
        if not (97 + i) in dic:
            an =  inp + chr(97+i)
            break
print(an)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    if len(s) < 26:
        for c in string.ascii_lowercase:
            if c not in s:
                return s + c
    if s == ''.join([c for c in string.ascii_lowercase][::-1]):
        return -1
    for i in range(25,-1,-1):
        c = s[i]
        if max([_ for _ in s[i:]]) == c:
            continue
        t = [_ for _ in s[i:]]
        t.sort()
        ci = t.index(c)
        return s[:i] + t[ci+1]


print(main())

Solution (Python):
s = list(input())
t = [a for a in "abcdefghijklmnopqrstuvwxyz"]
if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    if len(s) < 26:
        for i in t:
            if i not in s:
                s += i
                break
        print("".join(s))
    else:
        i = 25
        p = s[i]
        while s[i - 1] > s[i] and i > 0:
            i -= 1
        q = ""
        for k in sorted(set(t) - set(s[:i])):
            if k > s[i - 1]:
                q = k
                break
        print("".join(s[:i - 1]) + q)

Solution (Python):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        s = []
        for i in range(1, len(S))[::-1]:
            s += [S[i]]
            r = [x for x in s if x > S[i-1]]
            if r:
                print(S[:i-1] + sorted(r)[0])
                break
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Solution (Python):


alp = 'abcdefghijklmnopqrstuvwxyz'
S = input()
if S == alp[::-1]:
    print(-1)
else:
    if len(S) == len(alp):
        l = list(S)
        s = []
        for i in range(1, len(S))[::-1]:
            s += [l[i]]
            r = sorted(x for x in s if x > l[i-1])
            if r:
                l = l[:i-1] + [r[0]]
                break
        print(''.join(l))
    else:
        for i in S : alp = alp.replace(i, '')
        print(S+alp[0])

Solution (Python):


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i-1
                
                
                q=[k for k in temp[p:] if k>temp[p]] 
                print("".join(temp[:p])+min(q))
                exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Solution (Python):

import bisect


S = input()




s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]



def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_



if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            c = a[0:i]
            d = a[i:len(a)]
            d = sorted(d)
            
            num = c.pop()
            ind = bisect.bisect_left(d, num)
            c.append(d[ind])
            print(func(c))
            break

Solution (Python):
import sys

N = input()
a = []
c = ['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']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,0,-1):
    a.append(l[i])
    if ord(l[i]) > ord(l[i-1]):
      for j in range(len(a)):
        if l[i-1] < a[j]:
          print(N[0:i-1]+a[j])
          sys.exit()

Solution (Python):
import sys
 
 
alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()
 
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l]+i)
        sys.exit()

Solution (Python):
import sys

N = input()
a = []
b = ['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']
c = ['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']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,0,-1):
    a.append(l[i])
    if ord(l[i]) > ord(l[i-1]):
      for j in range(len(a)):
        if l[i-1] < a[j]:
          print(N[0:i-1]+a[j])
          sys.exit()

Solution (Python):

import itertools

ALPHA = sorted([s for s in 'zyxwvutsrqponmlkjihgfedcba'])


def main():
    S = input().strip()

    if 'zyxwvutsrqponmlkjihgfedcba' == S:
        return '-1'

    if len(set(ALPHA) - set([s for s in S])) != 0:
        return S + sorted(set(ALPHA) - set([s for s in S]))[0]

    for i in range(len(S) - 1, 0, -1):
        if S[i - 1] > S[i]:
            pass
        else:
            break

    for a in sorted(set(ALPHA) - set(S[:i])):
        if a > S[i - 1]:
            return S[:i - 1] + a


if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys


alph="abcdefghijklmnopqrstuvwxyz"
allis=list(alph)
S=input()
if(S=="zyxwvutsrqponmlkjihgfedcba"):
    print(-1)
    sys.exit()

"""
if(S=="abcdefghijklmnopqrstuvwxyz"):
    print("b")
    sys.exit()
"""
for i in alph:
    if(i not in S):
        print(S+i)
        sys.exit()
        
"""
outp=""
for i in range(len(S)):
    if(S[i]==alph[i]):
        outp+=S[i]
    else:
        outp=outp[:-1]
        outp=outp+alph[i]
        break
"""
l=-1
for i in range(len(S)-1)[::-1]:
    if(ord(S[i])<ord(S[i+1])):
        l=i
        break
        
x=sorted(S[i+1:])
for i in x:
    if(i>S[l]):
        print(S[:l]+i)
        sys.exit()
print("b")

Solution (Python):

p = lambda  x: x

s = input()		


if s == "zyxwvutsrqponmlkjihgfedcba":
	print("-1")
	exit(0)


from collections import defaultdict
d = defaultdict(int)

S = "abcdefghijklmnopqrstuvwxyz"
for key in S:
	d[key] = 0


for key in s:
	d[key] += 1

ans=""
for k, v in sorted(d.items(), key=lambda x: x[0]):
	
	if int(v)==0:
		ans = s + k
		print(ans)
		exit(0)




stock=""
for i in range(25, -1, -1):
	k = s[i]
	b=""
	p(i)
	p(k)
	for a in stock:
		p(a)
		if k < a:
			if b!="":
				if a < b: b = a
			else:
				b = a
	if b!="":
		ans = s[:i] + b
		print(ans)
		exit(0)
	stock += k
	p(b)
	
	












print("-1")

Solution (Python):
S = input()
a = [chr(ord('a') + i) for i in range(26)]
for l in S:
    a.remove(l)
if a != []:
    print(S+a[0])
else:
    b = []
    k = 1
    for l in reversed(S):
        b.append(l)
        b.sort()
        if b[-1] != l:
            print(S[0:-k]+b[b.index(l)+1])
            break
        k+=1
    else:
        print(-1)

Solution (Python):
s = list(input())
if sorted(s, reverse=True) == s and len(s) == 26:
    print(-1)
    quit()
for i in range(0, 26):
    if chr(97 + i) not in s and len(s) != 26:
        print(''.join(s) + chr(97+i))
        quit()

while len(s) > 0:
    while ord(s[-1]) < ord('z'):
        s[-1] = chr(ord(s[-1])+1)
        if len(s) == len(set(s)):
            print(''.join(s))
            quit()
    del s[-1]

Solution (Python):
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'
b = [i for i in a if i not in s]
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif b:
    print(s + b[0])
else:
    for i in range(1, len(s) + 1):
        if s[-i:][0] != sorted(s[-i:], reverse=True)[0]:
            b = [j for j in a if j not in s[:-i+1] and j > s[-i:][0]][0]
            if i == 26:
                print(chr(ord(s[0]) + 1))
            else:
                print(s[:-i] + b)
            break

Solution (Python):





s = str(input())


s_list = list(s)
s_length = len(s)
last_str = s[-1]

alphabet = ['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']

if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)

elif s_length < 26:
    rest_list = list(set(alphabet) - set(s_list))
    rest_list.sort()
    print(s + rest_list[0])

else:
    trans_list = []
    for i in reversed(range(1,len(s))):
        trans_list.append(alphabet.index(s_list[i]))
        min_trans_list = min(trans_list)

        if alphabet.index(s_list[i-1]) < alphabet.index(s_list[i]):
            last_list = [k for k in trans_list if k > alphabet.index(s_list[i-1])]

            print(s[:i-1] + alphabet[last_list[0]])

            break

Solution (Python):

CHR_A = ord("a") 
NUM_CHR = 26
CHR_LIST = [chr(CHR_A+i) for i in range(NUM_CHR)]

def addChar(s, chr_list):
    for char in chr_list:
        if not(char in s):
            s = s+char
            break
    return s

def removeTail(s):
    for i in range(1,NUM_CHR):
        if ord(s[-1])<ord(s[-2]):
            s = s[:-1]
        else:
            s = s[:-1]
            last_s = s[-1]
            s = s[:-1:1]
            candidate = [chr(i) for i in range(ord(last_s)+1, CHR_A+NUM_CHR)]
            s = addChar(s, candidate)
            break
    return s

def main():
    
    s = input()

    
    if s == ''.join(CHR_LIST[::-1]):
        print(-1)
    
    
    
    elif len(s) <= 25:
        s = addChar(s, CHR_LIST)
        print(s)
    
    
    
    else:
        s = removeTail(s)
        print(s)
    
if __name__ == "__main__":
    main()

Solution (Python):
def rev26(s):
    for i in range(len(s) - 1, 0, -1):
        if (s[i] > s[i - 1]):
            chars = sorted(s[i:])
            for j in range(len(chars)):
                if chars[j] > s[i - 1]:
                    return s[0:i - 1] + chars[j]

    return "-1"
    

s = input()

if len(s) == 26:
    print(rev26(s))

else:
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    for i in range(len(s)):
        alphabets = alphabets.replace(s[i], "")

    print(s + alphabets[0])

Solution (Python):
import sys
S = []

S = input()

Len = len(S)

Cnt = [0 for i in range(26)]
Chk = 0

S2 = 'abcdefghijklmnopqrstuvwxyz'

if Len == 26:
    for i in range(Len):
        TmpS = S[i]
        for j in range(26):
            if S2[j] == TmpS:
                Cnt[j] += 1
                if Cnt[j] > 1:
                    print('-1')
                    sys.exit()
            break

        
    Cnt = [0 for i in range(26)]
    
    for i in range(26):
        TmpI2 = 25 - i
        TmpI1 = 25 - i - 1
        if TmpI2 <= 0:
            print('-1')
            sys.exit()
            
        TmpS2 = S[TmpI2]
        TmpS1 = S[TmpI1]
        
        TmpS1N = 26
        TmpS2N = 26
        for j in range(26):
            if TmpS2 == S2[j]:
                TmpS2N = j

            if TmpS1 == S2[j]:
                TmpS1N = j
            
            if (TmpS1N < 26) and (TmpS1N < 26):
                break
        
        if TmpS1N < TmpS2N:
            for j in range(26):
                TmpI3 = 25 - j
                TmpS3 = S[TmpI3]
                if TmpS3 == S2[TmpS1N]:
                    break
                for j2 in range(26):
                    if TmpS3 == S2[j2]:
                        TmpS3N = j2
                        
                        if TmpS3N < TmpS1N:
                            Cnt[TmpS3N] = 1
                        break
                        
                    
            
            S = S[:TmpI1]
            Len = len(S)
            Cnt[TmpS1N] = 1
            
            break

                
for i in range(Len):
    TmpS = S[i]
    
    for j in range(26):
        if S2[j] == TmpS:
            Cnt[j] += 1
            if Cnt[j] > 1:
                Chk = 1
            break
    
    if (Chk==1):
        print('-1')
        sys.exit()
        
for i in range(26):
    
    if Cnt[i] == 0:
        S = S + S2[i]
        break

print(S)

Solution (Python):
S=input()
row='abcdefghijklmnopqrstuvwxyz'
row=list(row)
if len(S)!=26:
    for letter in S:
        row.remove(letter)
    print(S+row[0])
    
else:
    if S=='zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        S_=[]
        for i in range(25,1,-1):
            if S[i-1]<S[i]:
                for j in range(i-1):
                    S_.append(S[j])
                x=row.index(S[i-1])
                for j in range(x+1,27,1):
                    if row[j] not in S_:
                        S_.append(row[j])
                        break
                S_=''.join(S_)
                print(str(S_))
                break
        else:
            print(row[row.index(S[0])+1])

Solution (Python):
alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]

s = input()
ans = ''
if s == 'zyxwvutsrqponmlkjihgfedcba':
    ans = '-1'

elif len(s) == 26:
    pre = '`'
    end = 0
    for x in reversed(s):
        if ord(pre) > ord(x):
            ans = s[:end]
            break
        end -= 1
        pre = x
    for a in alphabet:
        if a not in ans and ord(a) > ord(ans[-1]):
            ans = ans[:len(ans)-1] + a
            break
else:
    for a in alphabet:
        if a not in s:
            ans = s + a
            break
print(ans)

Solution (Python):
import copy
S=raw_input()
M=list("abcdefghijklmnopqrsqtuvwxyz")


if len(S)==26:
	if S=="zyxwvutsrqponmlkjihgfedcba":
		print -1
		quit()
	else:
		S2=list(S)
		for i in S2[::-1]:
			idx=S2.index(i)
			for j in M:
				if j>i:
					j_idx=S2.index(j)
					S2[idx]=j
					S2[j_idx]=i
					str="".join(S2)
					if str>S:
						print str[:idx+1]
						quit()
					else:
						S2=list(S)
else:
	for i in S:
		M.remove(i)
	print S+M[0]

Solution (Python):
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

abc = "abcdefghijklmnopqrstuvwxyz"
s = S()
if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
if len(s) < 26:
    for a in abc:
        if not a in s:
            print(s+a)
            exit()
else:
    for i in range(len(s)-1):
        if s[-i-2] < s[-i-1]:
            ans = s[:-i-2]
            t = s[-i-2]
            for a in abc:
                if not a in ans and a > t:
                    print(ans+a)
                    exit()

Solution (Python):
S = input()
T = "abcdefghijklmnopqrstuvwxyz"
if len(S) != 26:
    for i in T:
        if i not in S:
            print(S+i)
            exit()
else:
    if S == "zyxwvutsrqponmlkjihgfedcba" :
        print(-1)
    else:
        dic = []
        for i in range(25,-1,-1):
            for j in dic:
                if j > S[i]:
                    print(S[:i]+j)
                    exit()
            dic.append(S[i])
            dic = sorted(dic)

Solution (Python):
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque








def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)


def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))




def main():

	S = input()
	
	if S == 'zyxwvutsrqponmlkjihgfedcba':
		print(-1)
		exit()

	set_al = set([chr(i) for i in range(97,123)])
	set_s = set(S)

	if len(S) != len(set_s):
		print("-1")

	availables = sorted(list(set_al - set_s), reverse = True)

	if availables:
		print(S+str(availables[-1]))
	else:
		f = False
		for i in range(len(S))[::-1]:
			chr_n = ord(S[i])

			while chr_n <= 122:
				if chr(chr_n) not in S:
					S = S[:-1]
					S += chr(chr_n)
					f = True
					break
				chr_n += 1

			if f:
				break
			S = S[:-1]

		print(S)


if __name__ == '__main__':
  main()