output_description: Print the amount of money that Iroha will hand to the cashier.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N K
      D_1 D_2 … D_K
attempt: # @oj: atcoder
  # @id: hitwanyang
  # @email: 296866643@qq.com
  # @date: 2020-08-13 22:50
  # @url:https://atcoder.jp/contests/abc042/tasks/arc058_a
  
  import sys, os
  from io import BytesIO, IOBase
  import collections, itertools, bisect, heapq, math, string
  from decimal import *
  
  # region fastio
  
  BUFSIZE = 8192
  
  BUFSIZE = 8192
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
  
  
  sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  
  
  # ------------------------------
  def main():
      n, k = map(int, input().split())
      d = list(map(int, input().split()))
      mx = 10000
      ans = 10000
      while mx >= 0:
          temp = str(mx)
          f = True
          for i in range(len(temp)):
              if int(temp[i]) in d:
                  f = False
                  break
          if f and mx >= n:
              ans = min(ans, mx)
          mx = mx - 1
      print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  Iroha is very particular about numbers. There are K digits that she dislikes:
  D_1, D_2, ..., D_K.
  
  She is shopping, and now paying at the cashier. Her total is N yen (the
  currency of Japan), thus she has to hand at least N yen to the cashier (and
  possibly receive the change).
  
  However, as mentioned before, she is very particular about numbers. When she
  hands money to the cashier, the decimal notation of the amount must not
  contain any digits that she dislikes. Under this condition, she will hand the
  minimum amount of money.
  
  Find the amount of money that she will hand to the cashier.
samples: [{"input": "1000 8\n    1 3 4 5 6 7 8 9", "output": "2000\n    \n\nShe dislikes all digits except 0 and 2.\n\nThe smallest integer equal to or greater than N=1000 whose decimal notation\ncontains only 0 and 2, is 2000.\n\n* * *"}, {"input": "9999 1\n    0", "output": "9999"}]