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

d = tuple(map(str, input().split()))

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

    b = True

    for s in tuple(str(i)):

        if s in d:

            b = False

            break

    if b:

        print(i)

        exit()

import itertools

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

d = list(map(int, input().split()))

u = []

for i in range(0, 10):

    if i not in d:

        u.append(i)

for j in range(1, 6):

    for i in itertools.product(u, repeat=j):

        t = int("".join(map(str, i)))

        if n <= t <= 100000:

            print(t)

            exit()

n, k = list(map(int, input().split()))
d = tuple(map(str, input().split()))
for i in range(n, 10**9):
    b = True
    for s in tuple(str(i)):
        if s in d:
            b = False
            break
    if b:
        print(i)
        exit()

import itertools

n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
u = []
for i in range(0, 10):
    if i not in d:
        u.append(i)
for j in range(1, 6):
    for i in itertools.product(u, repeat=j):
        t = int("".join(map(str, i)))
        if n <= t <= 100000:
            print(t)
            exit()

+import itertools + -d = tuple(map(str, input().split())) -for i in range(n, 10**9): -    b = True -    for s in tuple(str(i)): -        if s in d: -            b = False -            break -    if b: -        print(i) -        exit() +d = list(map(int, input().split())) +u = [] +for i in range(0, 10): +    if i not in d: +        u.append(i) +for j in range(1, 6): +    for i in itertools.product(u, repeat=j): +        t = int("".join(map(str, i))) +        if n <= t <= 100000: +            print(t) +            exit()