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

D = set(list(eval(input())))



for k in range(N, 20 * N):

    if len(set(list(str(k))) & D) == 0:

        print(k)

        exit()

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

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



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

    if set(list(str(i))) <= D:

        print(i)

        exit()



N, K = list(map(int, input().split()))
D = set(list(eval(input())))
for k in range(N, 20 * N):
    if len(set(list(str(k))) & D) == 0:
        print(k)
        exit()

N, K = list(map(int, input().split()))
D = set(map(str, list(range(10)))) - set(list(input().split()))
for i in range(N, 100 * N):
    if set(list(str(i))) <= D:
        print(i)
        exit()

-D = set(list(eval(input()))) -for k in range(N, 20 * N): -    if len(set(list(str(k))) & D) == 0: -        print(k) +D = set(map(str, list(range(10)))) - set(list(input().split())) +for i in range(N, 100 * N): +    if set(list(str(i))) <= D: +        print(i)