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

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



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

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

    if i>=n and len(D&num)==0:

        print(i)

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

D=set(list(map(str,input().split())))



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

    num=set(list(str(i)))

    if i>=n and len(D&num)==0:

        print(i)

        exit()
n, k = list(map(int, input().split()))
D = set(list(map(int, input().split())))
for i in range(n, 10 * n):
    num = set(list(map(int, str(i))))
    if i >= n and len(D & num) == 0:
        print(i)
        exit()

n, k = list(map(int, input().split()))
D = set(list(map(str, input().split())))
for i in range(n, 10 * n):
    num = set(list(str(i)))
    if i >= n and len(D & num) == 0:
        print(i)
        exit()

-D = set(list(map(int, input().split()))) +D = set(list(map(str, input().split()))) -    num = set(list(map(int, str(i)))) +    num = set(list(str(i)))