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



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



n_list = list(str(n))

n_list = [int(num) for num in n_list]



num = {1,2,3,4,5,6,7,8,9,0}



d_set = set(d)

empty = set()

#print(set(n_list))

#print(d_set)

#print(set(n_list) & d_set)

while(1):

  n_list = list(str(n))

  n_list = [int(num) for num in n_list]

  if(set(n_list) & d_set == empty):

    print(n)

    break

  n += 1

  

import sys

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





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

d_set = set(d)



num_set = set([1,2,3,4,5,6,7,8,9,0])

enable = num_set - d_set

#print(type(enable))

#print(enable)





def dfs(s):

  #print(s)

  global ans

  # すでにN以上の場合はこの先を探索しない

  if s != "":

    if int(s) >= N:

      #print(s)

      ans.append(int(s))

      return



  for num in enable:

    if len(s) == 0 and num == 0:

      continue

    else:

      (dfs(s+str(num)))

    

  return



ans = []

dfs("")

#print(ans)

print((min(ans)))
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
n_list = list(str(n))
n_list = [int(num) for num in n_list]
num = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
d_set = set(d)
empty = set()
# print(set(n_list))
# print(d_set)
# print(set(n_list) & d_set)
while 1:
    n_list = list(str(n))
    n_list = [int(num) for num in n_list]
    if set(n_list) & d_set == empty:
        print(n)
        break
    n += 1

import sys

N, K = list(map(int, input().split()))
d = list(map(int, input().split()))
d_set = set(d)
num_set = set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
enable = num_set - d_set
# print(type(enable))
# print(enable)
def dfs(s):
    # print(s)
    global ans
    # すでにN以上の場合はこの先を探索しない
    if s != "":
        if int(s) >= N:
            # print(s)
            ans.append(int(s))
            return
    for num in enable:
        if len(s) == 0 and num == 0:
            continue
        else:
            (dfs(s + str(num)))
    return


ans = []
dfs("")
# print(ans)
print((min(ans)))

-n, k = list(map(int, input().split())) +import sys + +N, K = list(map(int, input().split())) -n_list = list(str(n)) -n_list = [int(num) for num in n_list] -num = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} -empty = set() -# print(set(n_list)) -# print(d_set) -# print(set(n_list) & d_set) -while 1: -    n_list = list(str(n)) -    n_list = [int(num) for num in n_list] -    if set(n_list) & d_set == empty: -        print(n) -        break -    n += 1 +num_set = set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) +enable = num_set - d_set +# print(type(enable)) +# print(enable) +def dfs(s): +    # print(s) +    global ans +    # すでにN以上の場合はこの先を探索しない +    if s != "": +        if int(s) >= N: +            # print(s) +            ans.append(int(s)) +            return +    for num in enable: +        if len(s) == 0 and num == 0: +            continue +        else: +            (dfs(s + str(num))) +    return + + +ans = [] +dfs("") +# print(ans) +print((min(ans)))