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

D = [Di for Di in input().split()]

for n in range(N, 1000000000):

    n = str(n)

    flag = True

    for i in range(len(str(n))):

        if n[i] in D:

            flag = False

            break

    if flag is True:

        print(n)

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

D = [Di for Di in input().split()]



for n in range(N, 1000000000):

    n = str(n)

    flag = True

    for ni in n:

        if ni in D:

            flag = False

            break

    if flag:

        print(n)

        exit()
N, K = list(map(int, input().split()))
D = [Di for Di in input().split()]
for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for i in range(len(str(n))):
        if n[i] in D:
            flag = False
            break
    if flag is True:
        print(n)
        exit()

N, K = list(map(int, input().split()))
D = [Di for Di in input().split()]
for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for ni in n:
        if ni in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

-    for i in range(len(str(n))): -        if n[i] in D: +    for ni in n: +        if ni in D: -    if flag is True: +    if flag: