import collections

import numpy as np

import sys

sys.setrecursionlimit(10000000)

import copy

#N=int(input())

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

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

for i in range(N,100000):

    t=set(map(int,list(str(i))))

    temp=D+list(t)

    temp2=set(temp)

    if len(temp)==len(temp2):

        #print(temp)

        #print(temp2)

        print(i)

        exit()

import collections

import numpy as np

import sys

sys.setrecursionlimit(10000000)

import copy

#N=int(input())

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

D=set(eval(input()))

while len(set(str(N))&D)>0:

    N+=1

print(N)

import collections
import numpy as np
import sys

sys.setrecursionlimit(10000000)
import copy

# N=int(input())
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
for i in range(N, 100000):
    t = set(map(int, list(str(i))))
    temp = D + list(t)
    temp2 = set(temp)
    if len(temp) == len(temp2):
        # print(temp)
        # print(temp2)
        print(i)
        exit()

import collections
import numpy as np
import sys

sys.setrecursionlimit(10000000)
import copy

# N=int(input())
N, K = list(map(int, input().split()))
D = set(eval(input()))
while len(set(str(N)) & D) > 0:
    N += 1
print(N)

-D = list(map(int, input().split())) -for i in range(N, 100000): -    t = set(map(int, list(str(i)))) -    temp = D + list(t) -    temp2 = set(temp) -    if len(temp) == len(temp2): -        # print(temp) -        # print(temp2) -        print(i) -        exit() +D = set(eval(input())) +while len(set(str(N)) & D) > 0: +    N += 1 +print(N)