# coding: utf-8;



def main():

    num = [0,1,2,3,4,5,6,7,8,9]

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

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

    usable_num = list(set(num) - set(d))



    while True:

        if len(set(map(int, str(n))) - set(usable_num)) == 0:

            break

        else:

            n += 1

    print(n)



if __name__ == '__main__':

    main()

# coding: utf-8;



def main():

    num = [0,1,2,3,4,5,6,7,8,9]

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

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

    usable_num = list(set(num) - set(d))



    while True:

        f = True

        for a in str(n):

            if int(a) not in usable_num:

                f = False

                break

        if f: break

        n += 1

    print(n)



if __name__ == '__main__':

    main()

# coding: utf-8;
def main():
    num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    n, k = list(map(int, input().split()))
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))
    while True:
        if len(set(map(int, str(n))) - set(usable_num)) == 0:
            break
        else:
            n += 1
    print(n)


if __name__ == "__main__":
    main()

# coding: utf-8;
def main():
    num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    n, k = list(map(int, input().split()))
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))
    while True:
        f = True
        for a in str(n):
            if int(a) not in usable_num:
                f = False
                break
        if f:
            break
        n += 1
    print(n)


if __name__ == "__main__":
    main()

-        if len(set(map(int, str(n))) - set(usable_num)) == 0: +        f = True +        for a in str(n): +            if int(a) not in usable_num: +                f = False +                break +        if f: -        else: -            n += 1 +        n += 1