n,k = list(map(int,input().split()))

d = input().replace(" ","")

for i in range(n,10**9):

  check = True

  for j in str(i):

    if j in d:

      check = False

      break

  if check:

    print(i)

    break
import copy

n,k = list(map(int,input().split()))

d = input().split()

nd = list(map(str,list(range(10))))

for i in d:

  nd.remove(i)

l = len(str(n))

if "0" in nd:

  a1 = 1

else:

  a1 = 0

alist = nd[a1:]

for _ in range(l-1):

  tlist = []

  for i in alist:

    for j in nd:

      tlist.append(i+j)

  alist = copy.copy(tlist)

alist.append(nd[a1]+nd[0]*l)

for i in alist:

  if n <= int(i):

    print(i)

    exit()
n, k = list(map(int, input().split()))
d = input().replace(" ", "")
for i in range(n, 10**9):
    check = True
    for j in str(i):
        if j in d:
            check = False
            break
    if check:
        print(i)
        break

import copy

n, k = list(map(int, input().split()))
d = input().split()
nd = list(map(str, list(range(10))))
for i in d:
    nd.remove(i)
l = len(str(n))
if "0" in nd:
    a1 = 1
else:
    a1 = 0
alist = nd[a1:]
for _ in range(l - 1):
    tlist = []
    for i in alist:
        for j in nd:
            tlist.append(i + j)
    alist = copy.copy(tlist)
alist.append(nd[a1] + nd[0] * l)
for i in alist:
    if n <= int(i):
        print(i)
        exit()

+import copy + -d = input().replace(" ", "") -for i in range(n, 10**9): -    check = True -    for j in str(i): -        if j in d: -            check = False -            break -    if check: +d = input().split() +nd = list(map(str, list(range(10)))) +for i in d: +    nd.remove(i) +l = len(str(n)) +if "0" in nd: +    a1 = 1 +else: +    a1 = 0 +alist = nd[a1:] +for _ in range(l - 1): +    tlist = [] +    for i in alist: +        for j in nd: +            tlist.append(i + j) +    alist = copy.copy(tlist) +alist.append(nd[a1] + nd[0] * l) +for i in alist: +    if n <= int(i): -        break +        exit()