import sys
N = int(input())
perm = list(map(int, sys.stdin.readline()[:-1].split(' ')))
if perm == sorted(perm): print(-1)
else:
for i in range(N-1, 0, -1):
if perm[i-1] > perm[i]:
for j in range(N-1, 0, -1):
if perm[i-1] > perm[j]:
perm[i-1], perm[j] = perm[j], perm[i-1]
perm = perm[:i] + sorted(perm[i:], reverse=True)
print(" ".join(map(str, perm)))
break
break