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

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



while True:

    S = str(N)

    t = 0

    for x in S:

        if x not in D:

            t += 1

    if t == len(S):

        print(S)

        break

    else:

        N += 1

import sys, math



def input():

    return sys.stdin.readline()[:-1]



def main():

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

    D = set(list(input().split()))

    for k in range(N,100001):

        s = str(k)

        f = 0

        for e in s:

            if e in D:

                f = 1

                break

        if f == 0:

            print(s)

            exit(0)



if __name__ == '__main__':

    main()

N, K = list(map(int, input().split()))
D = list(map(str, input().split()))
while True:
    S = str(N)
    t = 0
    for x in S:
        if x not in D:
            t += 1
    if t == len(S):
        print(S)
        break
    else:
        N += 1

import sys, math


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = list(map(int, input().split()))
    D = set(list(input().split()))
    for k in range(N, 100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)


if __name__ == "__main__":
    main()

-N, K = list(map(int, input().split())) -D = list(map(str, input().split())) -while True: -    S = str(N) -    t = 0 -    for x in S: -        if x not in D: -            t += 1 -    if t == len(S): -        print(S) -        break -    else: -        N += 1 +import sys, math + + +def input(): +    return sys.stdin.readline()[:-1] + + +def main(): +    N, K = list(map(int, input().split())) +    D = set(list(input().split())) +    for k in range(N, 100001): +        s = str(k) +        f = 0 +        for e in s: +            if e in D: +                f = 1 +                break +        if f == 0: +            print(s) +            exit(0) + + +if __name__ == "__main__": +    main()