output_description: Print the next word that appears after S in the dictionary, or `-1` if it
  doesn't exist.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
attempt: import math
  import bisect
  import collections
  import itertools
  import heapq
  import string
  import sys
  
  sys.setrecursionlimit(10**9)
  
  
  def gcd(a, b):
      return math.gcd  # 最大公約数
  
  
  def lcm(a, b):
      return (a * b) // math.gcd(a, b)  # 最小公倍数
  
  
  def iin():
      return int(input())  # 整数読み込み
  
  
  def isn():
      return input().split()  # 文字列読み込み
  
  
  def imn():
      return map(int, input().split())  # 整数map取得
  
  
  def iln():
      return list(map(int, input().split()))  # 整数リスト取得
  
  
  def iln_s():
      return sorted(iln())  # 昇順の整数リスト取得
  
  
  def iln_r():
      return sorted(iln(), reverse=True)  # 降順の整数リスト取得
  
  
  def join(l, s=""):
      return s.join(l)  # リストを文字列に変換
  
  
  def perm(l, n):
      return itertools.permutations(l, n)  # 順列取得
  
  
  def comb(l, n):
      return itertools.combinations(l, n)  # 組み合わせ取得
  
  
  def divisors(n):
      divisors = []
      for i in range(1, int(n**0.5) + 1):
          if n % i == 0:
              divisors.append(i)
              if i != n // i:
                  divisors.append(n // i)
      return divisors
  
  
  def is_prime(n):
      if n == 1:
          return False
      for i in range(2, int(n**0.5) + 1):
          if n % i == 0:
              return False
      return True
  
  
  def primes(n):
      is_prime = [True] * (n + 1)
      is_prime[0] = False
      is_prime[1] = False
      for i in range(2, int(n**0.5) + 1):
          if not is_prime[i]:
              continue
          for j in range(i * 2, n + 1, i):
              is_prime[j] = False
      return [i for i in range(n + 1) if is_prime[i]]
  
  
  def sieve_of_e(n):
      is_prime = [True] * (n + 1)
      is_prime[0] = False
      is_prime[1] = False
      for i in range(2, int(n**0.5) + 1):
          if not is_prime[i]:
              continue
          for j in range(i * 2, n + 1, i):
              is_prime[j] = False
      return is_prime
  
  
  s = input()
  S = list(s)
  a = string.ascii_lowercase
  od = collections.OrderedDict()
  for i in range(len(a)):
      od[a[i]] = 0
  for st in S:
      od[st] = 1
  for k, v in od.items():
      if v == 0:
          print(join(S) + k)
          exit()
  
  prev = S.pop()
  od[prev] = 0
  done = False
  for i in range(len(S)):
      prev = S.pop()
      od[prev] = 0
      target = False
      for k, v in od.items():
          if prev == k:
              target = True
              continue
          if target == True and v == 0:
              print(join(S) + k)
              done = True
              break
      if done == True:
          break
  if done == False:
      print(-1)
  
problem_description: 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}.
samples: [{"input": "atcoder", "output": "atcoderb\n    \n\n`atcoderb` is the lexicographically smallest diverse word that is\nlexicographically larger than `atcoder`. Note that `atcoderb` is\nlexicographically smaller than `b`.\n\n* * *"}, {"input": "abc", "output": "abcd\n    \n\n* * *"}, {"input": "zyxwvutsrqponmlkjihgfedcba", "output": "-1\n    \n\nThis is the lexicographically largest diverse word, so the answer is `-1`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwzyx", "output": "abcdefghijklmnopqrstuvx"}]