s=set(range(10))

n,k,*a=list(map(int,open(0).read().split()))

a=s-set(a) #使っていい数字

for t in range(n,100000):

    if set(list(map(int,list(str(t)))))<=a:

        print(t)

        break
x=lambda:input().split()

n,_=x();a=x();n=int(n)

while any(s in set(a)for s in str(n)):n+=1

print(n)
s = set(range(10))
n, k, *a = list(map(int, open(0).read().split()))
a = s - set(a)  # 使っていい数字
for t in range(n, 100000):
    if set(list(map(int, list(str(t))))) <= a:
        print(t)
        break

x = lambda: input().split()
n, _ = x()
a = x()
n = int(n)
while any(s in set(a) for s in str(n)):
    n += 1
print(n)

-s = set(range(10)) -n, k, *a = list(map(int, open(0).read().split())) -a = s - set(a)  # 使っていい数字 -for t in range(n, 100000): -    if set(list(map(int, list(str(t))))) <= a: -        print(t) -        break +x = lambda: input().split() +n, _ = x() +a = x() +n = int(n) +while any(s in set(a) for s in str(n)): +    n += 1 +print(n)