def main():

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

    D = input().split()



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

        if len(set(list(str(i))) & set(D)) == 0:

            print(i)

            break



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

d = [ int(x) for x in input().split() ]



def is_ok(x):

    while x != 0:

        if x % 10 in d:

            return False

        x //= 10

    return True



money = n

while True:

    if is_ok(n):

        print(n)

        break

    n += 1

def main():
    N, K = list(map(int, input().split()))
    D = input().split()
    for i in range(N, N * 10):
        if len(set(list(str(i))) & set(D)) == 0:
            print(i)
            break


main()

n, k = list(map(int, input().split()))
d = [int(x) for x in input().split()]


def is_ok(x):
    while x != 0:
        if x % 10 in d:
            return False
        x //= 10
    return True


money = n
while True:
    if is_ok(n):
        print(n)
        break
    n += 1

-def main(): -    N, K = list(map(int, input().split())) -    D = input().split() -    for i in range(N, N * 10): -        if len(set(list(str(i))) & set(D)) == 0: -            print(i) -            break +n, k = list(map(int, input().split())) +d = [int(x) for x in input().split()] -main() +def is_ok(x): +    while x != 0: +        if x % 10 in d: +            return False +        x //= 10 +    return True + + +money = n +while True: +    if is_ok(n): +        print(n) +        break +    n += 1