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



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



for i in range(N, 1000000):



  flag = 0



  for j in D:

    if str(j) in str(i):

      flag = 1

      break



  if flag == 0:

    print(i)

    exit()
def main():

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

    D = input().split()



    for i in range(N, N*10):

        if len(set(list(str(i))) & set(D)) == 0:

            print(i)

            break



main()
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
for i in range(N, 1000000):
    flag = 0
    for j in D:
        if str(j) in str(i):
            flag = 1
            break
    if flag == 0:
        print(i)
        exit()

def main():
    N, K = list(map(int, input().split()))
    D = input().split()
    for i in range(N, N * 10):
        if len(set(list(str(i))) & set(D)) == 0:
            print(i)
            break


main()

-N, K = list(map(int, input().split())) -D = list(map(int, input().split())) -for i in range(N, 1000000): -    flag = 0 -    for j in D: -        if str(j) in str(i): -            flag = 1 +def main(): +    N, K = list(map(int, input().split())) +    D = input().split() +    for i in range(N, N * 10): +        if len(set(list(str(i))) & set(D)) == 0: +            print(i) -    if flag == 0: -        print(i) -        exit() + + +main()