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

d= list(input().split())

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

    x=str(i)

    ans=True

    for j in range(len(x)):

        if x[j] in d:

            ans=False

    if ans:

        print(i)

        break

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

d=list(input().split())

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

    a=str(i)

    b=len(a)

    ans=True

    for j in a:

        if j in d:

            ans=False

            break 

    if ans:

        print(i)

        exit()
n, k = list(map(int, input().split()))
d = list(input().split())
for i in range(n, 10 * n + 1):
    x = str(i)
    ans = True
    for j in range(len(x)):
        if x[j] in d:
            ans = False
    if ans:
        print(i)
        break

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

-for i in range(n, 10 * n + 1): -    x = str(i) +for i in range(n, 10 * n): +    a = str(i) +    b = len(a) -    for j in range(len(x)): -        if x[j] in d: +    for j in a: +        if j in d: +            break -        break +        exit()