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

ds = list(input().split())



ans = total

while True:

  flag = False

  for d in ds:

    if d in list(str(ans)):

      flag = True

  if flag:

    ans += 1

  else:

    print(ans)

    exit(0)
total, k = list(map(int, input().split()))

ds = list(input().split())



for i in range(total,total*10+2):

  for d in ds:

    if d in list(str(i)):

      break

  else:

    print(i)

    exit(0)

total, k = list(map(int, input().split()))
ds = list(input().split())
ans = total
while True:
    flag = False
    for d in ds:
        if d in list(str(ans)):
            flag = True
    if flag:
        ans += 1
    else:
        print(ans)
        exit(0)

total, k = list(map(int, input().split()))
ds = list(input().split())
for i in range(total, total * 10 + 2):
    for d in ds:
        if d in list(str(i)):
            break
    else:
        print(i)
        exit(0)

-ans = total -while True: -    flag = False +for i in range(total, total * 10 + 2): -        if d in list(str(ans)): -            flag = True -    if flag: -        ans += 1 +        if d in list(str(i)): +            break -        print(ans) +        print(i)