def main():

    from sys import stdin

    n,k = list(map(int,stdin.readline().rstrip().split()))

    Ds = set(map(int,stdin.readline().rstrip().split()))



    ans = n

    while True:

        num = ans

        numset = set()

        while num != 0:

            r = num%10

            num = num//10

            numset.add(r)

        if numset & Ds == set({}):

            break;

        else:

            ans+=1

    

    print(ans)

main()
import io,sys

sys.setrecursionlimit(10**6)



def main():

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

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



    while True:

        temp = n

        num = []

        while temp > 0:

            num.append(temp%10)

            temp//=10

        

        flag = True

        for i in num:

            if i in D:

                flag = False

                break

        if flag:

            print(n)

            sys.exit()

        else:

            n+=1

main()
def main():
    from sys import stdin

    n, k = list(map(int, stdin.readline().rstrip().split()))
    Ds = set(map(int, stdin.readline().rstrip().split()))
    ans = n
    while True:
        num = ans
        numset = set()
        while num != 0:
            r = num % 10
            num = num // 10
            numset.add(r)
        if numset & Ds == set({}):
            break
        else:
            ans += 1
    print(ans)


main()

import io, sys

sys.setrecursionlimit(10**6)


def main():
    n, k = list(map(int, input().split()))
    D = list(map(int, input().split()))
    while True:
        temp = n
        num = []
        while temp > 0:
            num.append(temp % 10)
            temp //= 10
        flag = True
        for i in num:
            if i in D:
                flag = False
                break
        if flag:
            print(n)
            sys.exit()
        else:
            n += 1


main()

+import io, sys + +sys.setrecursionlimit(10**6) + + -    from sys import stdin - -    n, k = list(map(int, stdin.readline().rstrip().split())) -    Ds = set(map(int, stdin.readline().rstrip().split())) -    ans = n +    n, k = list(map(int, input().split())) +    D = list(map(int, input().split())) -        num = ans -        numset = set() -        while num != 0: -            r = num % 10 -            num = num // 10 -            numset.add(r) -        if numset & Ds == set({}): -            break +        temp = n +        num = [] +        while temp > 0: +            num.append(temp % 10) +            temp //= 10 +        flag = True +        for i in num: +            if i in D: +                flag = False +                break +        if flag: +            print(n) +            sys.exit() -            ans += 1 -    print(ans) +            n += 1