N,K=list(map(int,input().split()))

D=list(map(int,input().split()))

C=[]



for i in range(0,10):

  if i not in D:

    C.append(i)

#print(C)



for i in range(N,10**10):

  cnt=0

  for j in list(map(int,list(str(i)))):

    if j in C:

      cnt+=1

  if len(str(i))==cnt:

    print(i)

    exit()
N, K = list(map(int, input().split()))

D = list(map(int, input().split()))



for i in range(N, 10 * N + 1):

  A = list(map(int, str(i)))

  flag = 1

  for a in A:

    if a in D:

      flag = 0

      break

  if flag:

    print(i)

    exit()
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
C = []
for i in range(0, 10):
    if i not in D:
        C.append(i)
# print(C)
for i in range(N, 10**10):
    cnt = 0
    for j in list(map(int, list(str(i)))):
        if j in C:
            cnt += 1
    if len(str(i)) == cnt:
        print(i)
        exit()

N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
for i in range(N, 10 * N + 1):
    A = list(map(int, str(i)))
    flag = 1
    for a in A:
        if a in D:
            flag = 0
            break
    if flag:
        print(i)
        exit()

-C = [] -for i in range(0, 10): -    if i not in D: -        C.append(i) -# print(C) -for i in range(N, 10**10): -    cnt = 0 -    for j in list(map(int, list(str(i)))): -        if j in C: -            cnt += 1 -    if len(str(i)) == cnt: +for i in range(N, 10 * N + 1): +    A = list(map(int, str(i))) +    flag = 1 +    for a in A: +        if a in D: +            flag = 0 +            break +    if flag: