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

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

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

use -= D

use = list(use)

l = len(str(n))



ans = use.copy()

prev = use.copy()

digit = 0

while digit <= l:

    temp = []

    for x in prev:

        for v in use:

            temp.append(x+v)

    ans += temp

    prev = temp

    digit += 1



ans = list(map(int, ans))

ans.sort()



for num in ans:

    if num >= n:

        print(num)

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

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

use = set(map(str, list(range(10))))

use -= D



for num in range(n, 100*n):

    if use >= set(list(str(num))):

        print(num)

        exit()
n, k = list(map(int, input().split()))
D = set(input().split())
use = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
use -= D
use = list(use)
l = len(str(n))
ans = use.copy()
prev = use.copy()
digit = 0
while digit <= l:
    temp = []
    for x in prev:
        for v in use:
            temp.append(x + v)
    ans += temp
    prev = temp
    digit += 1
ans = list(map(int, ans))
ans.sort()
for num in ans:
    if num >= n:
        print(num)
        break

n, k = list(map(int, input().split()))
D = set(input().split())
use = set(map(str, list(range(10))))
use -= D
for num in range(n, 100 * n):
    if use >= set(list(str(num))):
        print(num)
        exit()

-use = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} +use = set(map(str, list(range(10)))) -use = list(use) -l = len(str(n)) -ans = use.copy() -prev = use.copy() -digit = 0 -while digit <= l: -    temp = [] -    for x in prev: -        for v in use: -            temp.append(x + v) -    ans += temp -    prev = temp -    digit += 1 -ans = list(map(int, ans)) -ans.sort() -for num in ans: -    if num >= n: +for num in range(n, 100 * n): +    if use >= set(list(str(num))): -        break +        exit()