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

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



while True:

    a = []

    m = n

    while m > 0:

        a.append(m % 10)

        m = m // 10

    

    j = 0

    for i in range(len(a)):

        if a[i] in d:

            break

        j += 1

        

    if j == len(a):

        print(n)

        exit(0)

    else:

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

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

flg = True

while flg:

    flg = False

    m = list(str(n))

    for i in m:

        if i in d:

            flg = True

            break

    if flg:

        n += 1

print(n)
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
while True:
    a = []
    m = n
    while m > 0:
        a.append(m % 10)
        m = m // 10
    j = 0
    for i in range(len(a)):
        if a[i] in d:
            break
        j += 1
    if j == len(a):
        print(n)
        exit(0)
    else:
        n += 1

n, k = list(map(int, input().split()))
d = list(input().split())
flg = True
while flg:
    flg = False
    m = list(str(n))
    for i in m:
        if i in d:
            flg = True
            break
    if flg:
        n += 1
print(n)

-d = list(map(int, input().split())) -while True: -    a = [] -    m = n -    while m > 0: -        a.append(m % 10) -        m = m // 10 -    j = 0 -    for i in range(len(a)): -        if a[i] in d: +d = list(input().split()) +flg = True +while flg: +    flg = False +    m = list(str(n)) +    for i in m: +        if i in d: +            flg = True -        j += 1 -    if j == len(a): -        print(n) -        exit(0) -    else: +    if flg: +print(n)