def judge(lst_D, number):

    str_number = str(number)

    for d in lst_D:

        if d in str_number:

            return False

    return True





def main():

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

    lst_D = list(input().split())



    cost = N

    while True:

        if judge(lst_D, cost):

            print(cost)

            break

        cost += 1





if __name__ == "__main__":

    main()
def main():

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

    lst_D = list(input().split())



    cost = N

    while True:

        for c in str(cost):

            if c in lst_D:

                break

        else:   # break しなかったときのみ実行される

            print(cost)

            break

        cost += 1





if __name__ == "__main__":

    main()
def judge(lst_D, number):
    str_number = str(number)
    for d in lst_D:
        if d in str_number:
            return False
    return True


def main():
    N, K = list(map(int, input().split()))
    lst_D = list(input().split())
    cost = N
    while True:
        if judge(lst_D, cost):
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

def main():
    N, K = list(map(int, input().split()))
    lst_D = list(input().split())
    cost = N
    while True:
        for c in str(cost):
            if c in lst_D:
                break
        else:  # break しなかったときのみ実行される
            print(cost)
            break
        cost += 1


if __name__ == "__main__":
    main()

-def judge(lst_D, number): -    str_number = str(number) -    for d in lst_D: -        if d in str_number: -            return False -    return True - - -        if judge(lst_D, cost): +        for c in str(cost): +            if c in lst_D: +                break +        else:  # break しなかったときのみ実行される