def abc042_c():

    price, len_hate_set = list(map(int, input().split()))

    hate_set = set([int(i) for i in input().split()])



    while True:

        if all([int(x) in set(range(0, 10)) - hate_set for x in [int(str(price)[i]) for i in range(len(str(price)))]]) and price >= price:

            return price



        price += 1





if __name__ == '__main__':

    print((abc042_c()))

def abc042_c():

    price, len_hate_set = list(map(int, input().split()))

    hate_set = set([int(i) for i in input().split()])

    usable_set = set(range(0, 10)) - hate_set

    

    while True:

        if all([int(x) in usable_set for x in [int(str(price)[i]) for i in range(len(str(price)))]]) and price >= price:

            return price



        price += 1





if __name__ == '__main__':

    print((abc042_c()))
def abc042_c():
    price, len_hate_set = list(map(int, input().split()))
    hate_set = set([int(i) for i in input().split()])
    while True:
        if (
            all(
                [
                    int(x) in set(range(0, 10)) - hate_set
                    for x in [int(str(price)[i]) for i in range(len(str(price)))]
                ]
            )
            and price >= price
        ):
            return price
        price += 1


if __name__ == "__main__":
    print((abc042_c()))

def abc042_c():
    price, len_hate_set = list(map(int, input().split()))
    hate_set = set([int(i) for i in input().split()])
    usable_set = set(range(0, 10)) - hate_set
    while True:
        if (
            all(
                [
                    int(x) in usable_set
                    for x in [int(str(price)[i]) for i in range(len(str(price)))]
                ]
            )
            and price >= price
        ):
            return price
        price += 1


if __name__ == "__main__":
    print((abc042_c()))

+    usable_set = set(range(0, 10)) - hate_set -                    int(x) in set(range(0, 10)) - hate_set +                    int(x) in usable_set