S = input().strip()

C = {chr(i):0 for i in range(97,123)}

n = len(S)

for a in S:

    C[a] += 1

flag = 0

for i in range(97,123):

    if C[chr(i)]==0:

        x = S+chr(i)

        flag = 1

        break

if flag==0:

    cnt = -2

    while cnt>=-n:

        b = S[cnt]

        A = []

        for i in range(n+cnt+1,n):

            if ord(b)<ord(S[i]):

                A.append(S[i])

        if len(A)>0:

            A = sorted(A)

            x = S[:cnt]+A[0]

            flag = 1

            break

        cnt -= 1

if flag == 1:

    print(x)

else:

    print((-1))
S = input().strip()

if len(S)<26:

    for i in range(97,123):

        if chr(i) not in S:

            print((S+chr(i)))

            break

else:

    flag = 0

    for i in range(24,-1,-1):

        if S[i]<S[i+1]:

            a = S[i]

            for j in range(25,i,-1):

                if S[j]>a:

                    print((S[:i]+S[j]))

                    flag = 1

                    break

            if flag==1:break

    if flag==0:

        print((-1))
S = input().strip()
C = {chr(i): 0 for i in range(97, 123)}
n = len(S)
for a in S:
    C[a] += 1
flag = 0
for i in range(97, 123):
    if C[chr(i)] == 0:
        x = S + chr(i)
        flag = 1
        break
if flag == 0:
    cnt = -2
    while cnt >= -n:
        b = S[cnt]
        A = []
        for i in range(n + cnt + 1, n):
            if ord(b) < ord(S[i]):
                A.append(S[i])
        if len(A) > 0:
            A = sorted(A)
            x = S[:cnt] + A[0]
            flag = 1
            break
        cnt -= 1
if flag == 1:
    print(x)
else:
    print((-1))

S = input().strip()
if len(S) < 26:
    for i in range(97, 123):
        if chr(i) not in S:
            print((S + chr(i)))
            break
else:
    flag = 0
    for i in range(24, -1, -1):
        if S[i] < S[i + 1]:
            a = S[i]
            for j in range(25, i, -1):
                if S[j] > a:
                    print((S[:i] + S[j]))
                    flag = 1
                    break
            if flag == 1:
                break
    if flag == 0:
        print((-1))

-C = {chr(i): 0 for i in range(97, 123)} -n = len(S) -for a in S: -    C[a] += 1 -flag = 0 -for i in range(97, 123): -    if C[chr(i)] == 0: -        x = S + chr(i) -        flag = 1 -        break -if flag == 0: -    cnt = -2 -    while cnt >= -n: -        b = S[cnt] -        A = [] -        for i in range(n + cnt + 1, n): -            if ord(b) < ord(S[i]): -                A.append(S[i]) -        if len(A) > 0: -            A = sorted(A) -            x = S[:cnt] + A[0] -            flag = 1 +if len(S) < 26: +    for i in range(97, 123): +        if chr(i) not in S: +            print((S + chr(i))) -        cnt -= 1 -if flag == 1: -    print(x) -    print((-1)) +    flag = 0 +    for i in range(24, -1, -1): +        if S[i] < S[i + 1]: +            a = S[i] +            for j in range(25, i, -1): +                if S[j] > a: +                    print((S[:i] + S[j])) +                    flag = 1 +                    break +            if flag == 1: +                break +    if flag == 0: +        print((-1))