def no_dislike_number(num, D):

    for dislike in D:

        if dislike in num:

            return False

    return True



MAX = 10000

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

D = input().split()

num = N

while(True):

    if no_dislike_number(str(num), D):

        print(num)

        break

    num += 1
def no_dislike_number(num, D):

    for digit in num:

        if digit in D:

            return False

    return True

    # for dislike in D:

    #     if dislike in num:

    #         return False

    # return True



MAX = 10000

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

D = input().split()

num = N

while(True):

    if no_dislike_number(str(num), D):

        print(num)

        break

    num += 1
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True


MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while True:
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

def no_dislike_number(num, D):
    for digit in num:
        if digit in D:
            return False
    return True
    # for dislike in D:
    #     if dislike in num:
    #         return False
    # return True


MAX = 10000
N, K = list(map(int, input().split()))
D = input().split()
num = N
while True:
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

-    for dislike in D: -        if dislike in num: +    for digit in num: +        if digit in D: +    # for dislike in D: +    #     if dislike in num: +    #         return False +    # return True