output_description: If it is possible to construct a Haiku by using each of the phrases once,
  print `YES` (case-sensitive). Otherwise, print `NO`.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      A B C
attempt: def equal(n, available):
      return n in available
  
  
  def less(n, available):
      return n < sorted(available)[0]
  
  
  def greater(n, available):
      return n > sorted(available, reverse=True)[0]
  
  
  # less(n, available) == True であること
  def upper_next(n, available):
      for v in sorted(available):
          if n < v:
              return v
      return 1 / 0
  
  
  n_str, _ = [v for v in input().split()]
  n_s = [0]
  n_s.extend([int(n_str[i : i + 1]) for i in range(len(n_str))])
  
  d_s = [int(v) for v in input().split()]
  
  available = set(list(range(10))) - set(d_s)
  
  # print("n", n_s, "d", d_s, "u", available)
  
  min_available = sorted(available)[0]
  max_available = sorted(available, reverse=True)[0]
  
  ans = [0]
  ans.extend([min_available] * (len(n_s) - 1))
  
  eq = True
  for i in range(1, len(n_s)):
      if eq:
          if equal(n_s[i], available):
              ans[i] = n_s[i]
              continue
          else:
              eq = False
              if less(n_s[i], available):
                  ans[i] = upper_next(n_s[i], available)
                  # 残りは最小値詰め
                  break
              else:
                  for j in range(i - 1, -1, -1):
                      if ans[j] == max_available:
                          ans[j] = min_available
                      else:
                          ans[j] = upper_next(ans[j], available)
                          break
                  break
  
  begin = 0
  if ans[0] == 0:
      begin = 1
  ans_val = "".join(map(lambda x: str(x), ans[begin:]))
  
  print(ans_val)
  
problem_description: Statement
  
  Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku
  consists of three phrases with 5, 7 and 5 syllables, in this order.
  
  To create a Haiku, Iroha has come up with three different phrases. These
  phrases have A, B and C syllables, respectively. Determine whether she can
  construct a Haiku by using each of the phrases once, in some order.
samples: [{"input": "5 5 7", "output": "YES\n    \n\nUsing three phrases of length 5, 5 and 7, it is possible to construct a Haiku.\n\n* * *"}, {"input": "7 7 5", "output": "NO"}]