Problem:
 Score : 300 points    Problem Statement Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K .  She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).  However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.  Find the amount of money that she will hand to the cashier.      Constraints  1 ≦ N < 10000  1 ≦ K < 10  0 ≦ D_1 < D_2 < … < D_K≦9  \{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}         Input The input is given from Standard Input in the following format:  N  K  D_1  D_2 … D_K       Output Print the amount of money that Iroha will hand to the cashier.        Sample Input 1 1000 8
1 3 4 5 6 7 8 9      Sample Output 1 2000  She dislikes all digits except 0 and 2 .  The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2 , is 2000 .       Sample Input 2 9999 1
0      Sample Output 2 9999

Solution (Python):
D, K = map(int, input().split())
S = set(input().split())
while any((c in S) for c in str(D)):
    D += 1
print(D)

Solution (Python):
def foo(D, S):
    while any((c in S) for c in str(D)):
        D += 1
    return D

D, K = map(int, input().split())
S = set(map(str, input().split()))
print(foo(D, S))

Solution (Python):
n, k = map(int, input().split())
A = list(input().split())

for i in range(n * 10):
    for j in str(n + i):
        if j in A:
            break
    else:
        print(n + i)
        break

Solution (Python):
N, K = map(int, input().split())
D = input().split()

def isok(yen, D):
    flag = True
    for y in yen:
        if y in D:
            flag = False
            break
    return flag

while True:
    if isok(str(N), D):
        print(N)
        break
    N += 1

Solution (Python):
n, k = map(int, input().split())
A = list(input().split())
for i in range(10 * n):
    for a in A:
        if a in str(n + i):
            break
    else:
        ans = n + i
        break
print(ans)

Solution (Python):
N, K = map(int, input().split())
Hate = list(map(int, input().split()))
D = [d for d in range(10) if d not in Hate]
D0 = D[:]
if 0 not in D:
    D0.insert(0, 0)
for d4 in D0:
    for d3 in D0:
        for d2 in D0:
            for d1 in D0:
                for d0 in D:
                    M = 10000 * d4 + 1000 * d3 + 100 * d2 + 10 * d1 + d0
                    if N <= M:
                        if 0 == D[0] or M <= 99:
                            print(M)
                            break
                        elif M <= 999 and d1 != 0:
                            print(M)
                            break
                        elif 1000 <= M <= 9999 and d1 != 0 and d2 != 0:
                            print(M)
                            break
                        elif 10000 <= M and d1 != 0 and d2 != 0 and d3 != 0:
                            print(M)
                            break
                else:
                    continue
                break
            else:
                continue
            break
        else:
            continue
        break
    else:
        continue
    break

Solution (Python):
N, K = map(int, input().split())
de_num = list(map(int, input().split()))
ok_num = []
cand_num = []
ans_num = []


for i in range(10):
  if i not in de_num:
    ok_num.append(i)


for i in ok_num:
  for j in ok_num:
    for k in ok_num:
      for l in ok_num:
        for m in ok_num:
          if len(str(N)) == 4:
            num = 10000*i + 1000*j + 100*k + 10*l + m
            cand_num.append(num)
            num_s = 1000*j + 100*k + 10* l +m
            cand_num.append(num_s)
          elif len(str(N)) == 3:
            num = 1000*j + 100*k + 10*l + m
            cand_num.append(num)
            num_s = 100*k + 10*l + m
            cand_num.append(num_s)
          elif len(str(N)) == 2:
            num = 100*k + 10*l + m
            cand_num.append(num)
            num_s = 10*l + m
            cand_num.append(num_s)
          elif len(str(N)) == 1:
            num = 10*l + m
            cand_num.append(num)
            num_s = m
            cand_num.append(num_s)
            

for cd in cand_num:
  if cd >= N:
    ans_num.append(cd)

print(min(ans_num))

Solution (Python):
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())

def ketajudge(x):
  while x != 0:
    if x%10 in d:
      return False
      break
    else:
      if x//10 == 0:
       return True
       break
    x = x//10 
  
  

for i in range(10*n):
  judge = n+i
  if ketajudge(judge) == True:
    print(judge)
    break

Solution (Python):
from itertools import product as p
n,k=map(int,input().split())
*d,=map(int,input().split())

cd={i for i in range(10)}-set(d)

*a,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=1)]))
*b,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=2)]))
*c,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=3)]))
*d,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=4)]))
*e,=filter(lambda x:x>=n,sorted([int("".join(map(str,i))) for i in p(cd,repeat=5)]))

print((a+b+c+d+e)[0])

Solution (Python):
N,K=map(int,input().split())
D=set(input())
while sum(i in D for i in str(N))>0:
    N+=1
print(N)

Solution (Python):
def dfs(x):
    if x > N * 10:
        return
    if x >= N:
        cand.append(x)
    for y in not_dislike:
        dfs(x*10 + y)

N, K = map(int, input().split())
D = set(int(x) for x in input().split())

not_dislike = set(range(10)) - D
cand = []
for x in not_dislike-set([0]):
    dfs(x)
print(min(cand, key=lambda x: abs(x-N)))

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N, N*10):
    for j in map(str, D):
        if j in list(str(i)):
            break
    else:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())

for i in range(N, N*10):
    for j in D:
        if j in list(str(i)):
            break
    else:
        print(i)
        break

Solution (Python):
n=int(input().split()[0])
d=input().split()
while True:
    v=True
    for i in str(n):
        if i in d:
            v=False
            break
    if v:
        print(n)
        break
    n+=1

Solution (Python):
price, amount = map(int, input().split())
hate_set = set(input().split())

while True:
    price_set = set([ a for a in str(price)])
    
    if hate_set & price_set == set():
        break
    else:
        price += 1

print(price)

Solution (Python):
N,K=map(int,input().split())
hate = input().split()
def check(number,hate):
    for i in range(K):
        if str(number).count(hate[i])!=0:return False
    return True
number=N
while not check(number,hate):
    number+=1
print(number)

Solution (Python):
N, K = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N,100000):
    flag = 0
    for x in str(i):
        if int(x) in L:
            flag = 1
    if flag == 0:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
D = list(input())

flag = True
while flag:
    flag = False
    tmp = str(N)
    for d in D:
        if d in tmp:
            N += 1
            flag = True
            break

print(N)

Solution (Python):
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,100000):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Solution (Python):
N,K = map(int,input().split())
dislike = [i for i in input().split()]
for num in range(N,10**6):
    ok = True
    for s in str(num):
        if s in dislike:
            ok = False
    if ok :
        print(num)
        break
    else:
        continue

Solution (Python):
n, k = map(int, input().split())
a = input().split()
d = [int(m) for m in a]
aset = set(a)
i = n
while True:
    k = list(str(i))
    klen = len(k)
    for j in range(klen):
        if k[j] in aset:
            i += 10 ** (klen - j - 1)
            i -= i % (10 ** (klen - j - 1))
            break
    else:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().strip().split())
setD = set(input().strip().split())
for i in range(N, 100000):
  if not setD.intersection(set([c for c in str(i)])):
    print(i)
    break

Solution (Python):
n,k=input().split()
n=int(n)
k=int(k)
d=input().split()
d=list(map(int,d))
a=[0]*10
flag=True
for i in d:
    a[i]+=1
while 1:
    flag=True
    tmp=n
    while tmp!=0:
        if(a[tmp%10]!=0):
            flag=False
            n+=1
            break
        tmp//=10
    if flag==True:
        print(n)
        break

Solution (Python):
n, k = [int(x) for x in input().split()]
d = set([x for x in input().split()])

while len(set(str(n)) & d):
    n += 1
print(n)

Solution (Python):
N,K = map(int,input().split())
D = set(input().split())

for i in range(N,100000):
    
    if not D & set(str(i)):
        break

print(i)

Solution (Python):
n, k = map(int, input().split())
like = list(map(str, set(range(10)) - set(map(int, input().split()))))

while True:
  count = 0
  for c in str(n):
    if c in like:
      count += 1
      
  if count == len(str(n)):
    print(n)
    break
  
  n += 1

Solution (Python):
n, k = map(int, input().split())
d = input().split()
for r in range(n, n*10):
    s = "{}".format(r)
    for x in d:
        if x in s:
            break

    else:
        print(r)
        break

Solution (Python):
from itertools import product
n, k = map(int, input().split())
d = list(map(int, input().split()))

a = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(d)

a = sorted(list(a))
l = len(str(n))
c = ""
for i in range(l):
    c += str(a[-1])

if int(c) < n:
        if a[0] == 0:
            ans = str(a[1])
        else:
            ans = str(a[0])
        for i in range(l):
            ans += str(a[0])
        ans = int(ans)
else:
    ans = 10000
    for v in product(a, repeat=l):
        tmp = ""
        for i in v:
            tmp += str(i)
        if int(tmp) >= n:
            ans = min(ans, int(tmp))
print(ans)

Solution (Python):
N, K = map(int, input().split())
d=list(map(int,(input().split())))
ans = 0
for i in range(N,100000):
    temp = str(i)
    n_len = len(temp)
    for j in range(n_len):
        if int(temp[j]) in d:
            break
        elif j == n_len-1:
            ans = 1
            break
    if ans == 1:
        print(temp)
        break

Solution (Python):
N, K = map(int, input().split())
D = input().split()

for R in range(N, N * 10):
    S = '{}'.format(R)
    for d in D:
        if d in S:
            break
    else:
        print(R)
        break

Solution (Python):
def fukumu(D, kazu):
    for i in str(kazu):
        if D.count(i) == 0:
            continue
        else:
            return True
    return False

def keisan(N, D):
    kazu = N
    while fukumu(D, kazu):
        kazu += 1
    return kazu

N, K = [int(i) for i in input().split()]
D = input().split()
print(keisan(N,D))

Solution (Python):
n,k = map(int,input().split())
B = list(map(int,input().split()))
A = [i for i in range(0,10)]
for number in B:
    A.remove(number)

for i in range(n,10*n+1):
    for j in str(i):
        if not int(j) in A:
            break
    else:
        print(i)
        exit()

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
l=[0,1,2,3,4,5,6,7,8,9]
for i in range(k):
  l.remove(d[i])
L=[]
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        for j5 in range(len(l)):
          L.append(l[j1]*10000+l[j2]*1000+l[j3]*100+l[j4]*10+l[j5])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      for j4 in range(len(l)):
        L.append(l[j1]*1000+l[j2]*100+l[j3]*10+l[j4])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    for j3 in range(len(l)):
      L.append(l[j1]*100+l[j2]*10+l[j3])
for j1 in range(len(l)):
  for j2 in range(len(l)):
    L.append(l[j1]*10+l[j2])
for j1 in range(len(l)):
  L.append(l[j1])
L.sort()
for k in range(len(L)):
  if L[k]>=n:
    x=L[k]
    break
print(x)

Solution (Python):
n, k = map(int, input().split())
d = list(map(int, input().split()))
ok = [i for i in range(10) if i not in d]
ans = []

def solve(pay):
	if pay == "00000":
		return
	if pay != "" and int(pay) >= n:
		ans.append(pay)
		return
	for c in ok:
		solve(pay + str(c))
	return

solve("")
print(min(list(map(int, ans))))

Solution (Python):
N,K=map(int,raw_input().split())
D=map(int,raw_input().split())

U=[i for i in range(10) if i not in D]

Keta=1
while True:
    if N>U[-1]*(sum(10**(i) for i in range(Keta))):
        Keta+=1
    else:
        break

N_copy=N

Result=[]
for k in range(Keta):

    for u in U:
        if u*(10**(Keta-k-1))+U[-1]*(sum(10**(i) for i in range(Keta-k-1)))>=N_copy:
            Result.append(u)
            N_copy-=u*(10**(Keta-k-1))
            break



    if N_copy<=0:
        while len(Result)<Keta:
            Result.append(U[0])
        break

Ans=sum(Result[i]*(10**(Keta-i-1)) for i in range(len(Result)))
print Ans

Solution (Python):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
while True:
    s = str(n)
    poss = False
    for i in s:
        if int(i) in a:
            poss = True
            break
    if not poss:
        print(n)
        exit(0)
    n += 1

Solution (Python):
import sys
line = []
for i in sys.stdin.readlines():
    line.append(i.rstrip())
data = line.pop(0).split(" ")
num_list = line.pop().split(" ")

def pick_up(num_list):
    use_list = ['0','1','2','3','4','5','6','7','8','9']
    for i in num_list:
        use_list.remove(i)
    return use_list

def advance(n_list, num):
    n_list[len(n_list)-1] += 1
    while((num) in n_list):
        chk = n_list.index(num)
        if chk == 0:
            return [0 for i in range(len(n_list))]
        else:
            n_list[chk] = 0
            n_list[chk-1] += 1
    return n_list

def solve(num, num_list):
    use_list = pick_up(num_list)
    ans_list = [0 for i in range(len(num))]
    count = 0

    while(count < len(use_list)**len(ans_list)):
        ans_num = ""
        for i in ans_list:
            ans_num += use_list[i]
        if (int(ans_num) - int(num) >= 0):
            break
        ans_list = advance(ans_list, len(use_list))
        count += 1

    if count == len(use_list)**len(ans_list):
        ans_num = ""
        if use_list[0] != "0":
            for i in range(len(num)+1):
                ans_num += use_list[0]
        else:
            ans_num += use_list[1]
            for i in range(len(num)):
                ans_num += use_list[0]
    
    return ans_num
    
def main():
    print(solve(data[0], num_list))
    
if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    for i in range(n, 10**6):
        s = str(i)
        for d in ds:
            if str(d) in s:
                f = False
                break
            else:
                f = True
        if f:
            print(i)
            sys.exit()
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    for i in range(n, 10**6):
        s = str(i)
        for d in ds:
            if str(d) in s:
                f = False
                break
            else:
                f = True
        if f:
            print(i)
            sys.exit()
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    for i in range(n, 10**6):
        s = str(i)
        for d in ds:
            if str(d) in s:
                f = False
                break
            else:
                f = True
        if f:
            print(i)
            sys.exit()
if __name__ == "__main__":
    main()

Solution (Python):

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

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)


for level in range(6):
    if N // (10 ** level) < 1: break

    

    
def pay(pos, tmp):
    
    if pos > level or tmp >= N:
        if tmp >= N:
            
            return tmp
        else: return 10000
    
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    
    return ret

print(pay(0, 0))

Solution (Python):

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

Db = []
for Di in range(10):
    if Di not in D: Db.append(Di)


for level in range(6):
    if N // (10 ** level) < 1: break

    
memo = [None] * ((level + 1) * 10000)
    
def pay(pos, tmp):
    
    if pos > level or tmp >= N:
        if tmp >= N:
            
            return tmp
        else: return 10000
    elif memo[pos * 10000 + tmp] != None: return memo[pos * 10000 + tmp]
    rets = []
    for Dbi in Db:
        add = Dbi * (10 ** pos)
        rets.append(pay(pos + 1, tmp + add))
    ret = min(rets)
    if memo[pos * 10000 + tmp] == None: memo[pos * 10000 + tmp] = ret    
    return ret

print(pay(0, 0))

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())

for i in range(N, 10000 * 10):
    if len(set(str(N)) & D) >= 1:
        N += 1
    else:
        print(N)
        break

Solution (Python):
def main():
    n, _ = map(int, input().split())
    ds = set(input().split())

    while any(c in ds for c in iter(str(n))):
        n += 1

    print(n)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

n, k = map(int, input().split())
D = [int(x) for x in input().split()]


def dfs(s: str, m: int) -> None:
    if s != "" and int(s) >= n:
        print(s)
        sys.exit()

    if len(s) == m:
        return

    for i in range(10):
        if i not in D:
            dfs(str(i) + s, m)


for i in range(sys.maxsize):
    dfs("", i)

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())

for i in range(10**6):
    if len(set(str(N)) & D) >= 1:
        N += 1
    else:
        print(N)
        break

Solution (Python):
import itertools
N,K = input().split()
D = list(map(int,input().split()))
int_list = set(range(10))
like = list(int_list - set(D))
like.sort()
min_cost = 10**6
for e in itertools.product(like,repeat = len(N)):
    result = 0
    for i in range(len(N)):
        result += e[i] * pow(10,i)
    if int(N) <= result < min_cost:
        min_cost = result
if min_cost == 10**6:
    head = like[0] if like[0] > 0 else like[1]
    min_cost = head * pow(10,len(N))
    for i in range(len(N)):
        min_cost += like[0] * pow(10,i)
print(min_cost)

Solution (Python):
N,K=map(int,input().split())
D=set(input().split())

for i in range(N,10**10):
    if set(str(i)) & D==set():
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
D = input().split()
D_inv = set([str(i) for i in range(10)]) - set(D)

ans = n
while not set(list(str(ans))).issubset(D_inv):
    ans += 1
print(ans)

Solution (Python):

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

N = [int(x) for x in list(str(n))]
D_inv = sorted(list(set(range(10)) - set(D)))

m = len(N) + 1 
for i in range(len(N)):
    if N[i] in D:
        m = i
        break

if m == len(N) + 1:
    print(n)
    exit()

n = len(N) + 1 
for i in range(m + 1):
    if N[i] < D_inv[len(D_inv) - 1]:
        n = i

ans = 0
if n == len(N) + 1: 
    if D_inv[0] == 0:
        ans += D_inv[1] * (10 ** len(N))
    else:
        ans += D_inv[0] * (10 ** len(N))
    for i in range(len(N)):
        ans += D_inv[0] * (10 ** (len(N) - 1 - i))
else:
    for i in range(len(N)):
        if i < n:
            ans += N[i] * (10 ** (len(N) - 1 - i))
        if i == n: 
            for j in D_inv:
                if j > N[i]:
                    ans += j * (10 ** (len(N) - 1 - i))
                    break
        if i > n:
            ans += D_inv[0] * (10 ** (len(N) - 1 - i))
print(ans)

Solution (Python):
N, K = map(int, input().split(" "))
list_num = ["0","1","2","3","4","5","6","7","8","9"]
D =  input().split(" ")

use_num = list(set(list_num) - set(D))
ok = []

for a in use_num:
    ok.append(a)
    for b in use_num:
        ok.append(a+b)
        for c in use_num:
            ok.append(a+b+c)
            for d in use_num:
                ok.append(a+b+c+d)
                for e in use_num:
                    ok.append(a+b+c+d+e)
ans = []
for i in ok:
    if int(i) >= N:
        ans.append(int(i))

print(min(ans))

Solution (Python):
N, K = [int(_) for _ in input().split()]
D = [int(_) for _ in input().split()]
for i in range(N, 100000):
    is_possible = True
    for d in D:
        if str(d) in str(i):
            is_possible = False
            break
    if is_possible:
        print(i)
        exit()

Solution (Python):
n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ok = [1 for i in range(10)]
for i in range(len(d)):
    ok[d[i]] = -1
for i in range(n, 100000):
    complete = True
    for j in range(len(str(i))):
        if ok[int(str(i)[j])] == -1:
            complete = False
            break
    if complete:
        print(i)
        exit()

"""
import copy
def listToString(_list, split=""):
    maped_list = map(str, _list)  
    mojiretu = split.join(maped_list)
    return mojiretu

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ok = [1 for i in range(10)]
for i in range(len(d)):
    ok[d[i]] = -1

money = [0]
for i in range(len(str(n))):
    money.append(int(str(n)[i]))

for i in reversed(range(1, len(money))):
    for j in range(money[i], 10+money[i]):
        _j = j % 10
        if ok[_j] == 1:
            if _j >= money[i]:
                money[i] = _j
                break
            else:
                money[i] = _j


while True:
    if money[0] != 0:
        break
    else:
        del(money[0])


for i in range(len(money)):
    for j in range(10):
        if ok[j] == 1:
            tmpMoney = copy.deepcopy(money)
            tmpMoney[i] = j
            
            if int(listToString(tmpMoney)) >= n:
                
                money[i] = j
                break
print(int(listToString(money)))
"""

Solution (Python):
import sys

N, K = map(int, input().split())
D = [str(i) for i in input().split()]
ans = 0
now = N

for j in range(10**6):
    for i in list(str(now)):
        if i in D:
            now += 1
            break
    else:
        print(now)
        sys.exit()

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))

m = {}
for i in range(10):
    has_num = False
    for d in D:
        if d == i:
            has_num = True
            break
    if has_num:
        m[i] = True
    else:
        m[i] = False

min_cost = N
while(True):
    min_cost_list = list(str(min_cost))
    num_list = [int(i) for i in min_cost_list]
    has_num = False
    for n in num_list:
        if m[n]:
            has_num = True
    if has_num:
        min_cost += 1
        continue
    else:
        break
print(min_cost)

Solution (Python):
N,K = [int(i) for i in input().split()]
hate_numbers = [i for i in input().split()]


while True:
	is_okay = True
	for n in hate_numbers :
		if (str(N).find(n) == -1) :
			continue
		is_okay = False
		break
	
	if (is_okay == True) :
		print(N)
		break
	else :
		N += 1

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))

p = N
flag = True
while flag:
  pnum = list(map(int, str(p)))
  bp = [(i in D) for i in pnum]
  flag = sum(bp)
  if flag:
    p += 1
  
print(p)

Solution (Python):
N,K = map(int, input().split())
D = input().split()

usable = set([str(i) for i in range(10)]) - set(D)


for i in range(N, 10000*10):
    if set(list(str(i))).issubset(usable):
        print(i)
        break

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N, K = li_input()
    D = li_input()

    price = N
    while True:
        dislike = False
        for p in str(price):
            if int(p) in D:
                dislike = True
                break
        
        if not dislike:
            print(price)
            return
        
        price += 1
        


main()

Solution (Python):
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])
    usable_set = set(range(0, 10)) - hate_set
    
    while True:
        if all(map(lambda x: int(x) in usable_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())

Solution (Python):
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(price)[i]) for i in range(len(str(price)))])) and price >= price:
            return price

        price += 1


if __name__ == '__main__':
    print(abc042_c())

Solution (Python):
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    ans = price

    while True:
        if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
                   [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
            return ans

        ans += 1


if __name__ == '__main__':
    print(abc042_c())

Solution (Python):
def abc042_c():
    price, len_hate_set = map(int, input().split())
    hate_set = set([int(i) for i in input().split()])

    usable_list = list(set(range(0, 10)) - hate_set)

    ans = 0

    while True:
        if all(map(lambda x: int(x) in usable_list, [int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
            return ans

        ans += 1


if __name__ == '__main__':
    print(abc042_c())

Solution (Python):
N,K = map(int,input().split())
L = list(map(str,input().split()))

flag = 0
while flag == 0 :
    counter = 0
    for c in str(N) :
        if c not in L :
            counter += 1
        else :
            break
    if counter == len(list(str(N))) :
        flag = 1
    else :
        N += 1
print(N)

Solution (Python):
N,K = map(int,input().split())
L = list(map(str,input().split()))
flag = 0
while flag == 0 :
    counter = 0
    for c in str(N) :
        if c not in L :
            counter += 1
        else :
            break
    if counter == len(list(str(N))) :
        flag = 1
    else :
        N += 1
print(N)

Solution (Python):

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

all = [i for i in range(10)]

for Di in Dk:
    if Di in all:
        all.remove(Di)


ans = 0
for i in range(N,100000):
    tmp_list = map(int, list(str(i)))
    
    all_ok = True
    for c in tmp_list:
        if c in all:
            pass
        else:
            all_ok = False
            continue
    if all_ok == True:
        ans = i
        break

print(ans)

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))


def hate_num(n):
    for s in str(n):
        if int(s) in D:
            return False
    return True

while True:
    if hate_num(N):
        print(N)
        break
    N += 1

Solution (Python):
n, k = map(int, input().split())
d = set([int(i) for i in input().split()])

while True:
  N = set([int(i) for i in str(n)])
  if len(N.intersection(d)) == 0:
    print(n)
    break
  else:
    n += 1

Solution (Python):
n,k = map(int,input().split())
d = input().split()
price = n
ans = n
while True:
    flg = True
    for let in d:
        if str(n).count(let) > 0:
            flg = False
            break
    if flg != False:
        ans = n
        break
    n += 1
print(ans)

Solution (Python):

def solve(N, K, Ds):
    while True:
        c = set([int(c) for c in str(N)])
        if len(c.intersection(Ds)) == 0:
            return N
        N += 1


if __name__ == "__main__":
    N, K = map(int, input().split(" "))
    Ds = set(map(int, input().split(" ")))
    print(solve(N, K, Ds))

Solution (Python):


N, K = map(int, input().split())
D = list(map(str, input().split()))
flag = True
while flag:
    list_N = list(str(N))

    for num in D:
        if num in list_N:
            flag = True
            N += 1
            break
        else:
            flag = False
print(N)

Solution (Python):
def main():
    N, K = map(int, input().split())
    input_d = set(input().split())

    while True:
        n = set(list(str(N)))
        if not input_d & n:
            break
        N += 1
    print(N)


if __name__ == "__main__":
    main()