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

D = set(input().split())

while 1:

    E = set(str(N))

    if not(D&E):

        print(N)

        break

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

D = list(input().split())

for i in range(N,100001):

    n = str(i)

    k = 1

    for j in n:

        if j in D:

            k=0

            break

    if k:

        print(n)

        break
N, K = list(map(int, input().split()))
D = set(input().split())
while 1:
    E = set(str(N))
    if not (D & E):
        print(N)
        break
    N += 1

N, K = list(map(int, input().split()))
D = list(input().split())
for i in range(N, 100001):
    n = str(i)
    k = 1
    for j in n:
        if j in D:
            k = 0
            break
    if k:
        print(n)
        break

-D = set(input().split()) -while 1: -    E = set(str(N)) -    if not (D & E): -        print(N) +D = list(input().split()) +for i in range(N, 100001): +    n = str(i) +    k = 1 +    for j in n: +        if j in D: +            k = 0 +            break +    if k: +        print(n) -    N += 1