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):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, D: "List[int]"):
    tmp = N
    while True:
        i = tmp
        ng = False
        while i > 0:
            if (i % 10) in D:
                ng = True
                break
            i //= 10
        if not ng:
            print(tmp)
            return
        tmp += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    D = [ int(next(tokens)) for _ in range(K) ]  
    solve(N, K, D)

if __name__ == '__main__':
    main()

Solution (Python):
n_yen, k = map( int, input().split( ' ' ) )
unlike_numbers = set( map( int, input().split( ' ' ) ))




n_yen_str = str( n_yen )
each_strs = [ int( each ) for each in n_yen_str ]


for paid_yen in range( n_yen, 10* n_yen ):
	paid_yen_str = str( paid_yen )

	each_digit_strs = set( [int( each_digit ) for each_digit in paid_yen_str ] )
	if len( unlike_numbers & each_digit_strs ) == 0 :
		print( paid_yen )
		break

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

for i in range(10*n - n):
    c = str(n+i)
    
    for j in a:
        if j in c:
            break
    
    else:
        ans = c
        break
        
print(ans)

Solution (Python):
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) 
like=[]
hate.sort()
like.sort()
for i in range(10): 
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: 
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: 
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: 
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: 
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: 
	for man in like:
		for sen in like:
			for hyaku in like:
				for ju in like:
					for ichi in like:
						if man*10000+sen*1000+hyaku*100+ju*10+ichi>=n:
							kane=man*10000+sen*1000+hyaku*100+ju*10+ichi
							pointer=1
							break
					if pointer==1:
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break				

if pointer==1:
	print(kane)
else:
	print("Error!!")

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

for i in range(N, 1000000):
    tmp = list(str(i))
    count = 0
    for j in range(len(tmp)):
        if tmp[j] not in D:
            count += 1
    if count == len(tmp):
        ans = ''.join(tmp)
        break

print(ans)

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

l1 = [i for i in range(10) if i not in l]

for i in range(n,100000):
  l2 = [False]*len(str(i))
  for j in range(len(str(i))):
    if str(i)[j] not in l:
      l2[j] = True
      a = i
    else:
      break
  if all(l2):
    print(a)
    break
  else:
    continue

Solution (Python):
n, k = map(int, input().split())
d = set(map(str, input().split()))

num = n
while d.intersection(set(str(num))):
  num += 1
print(num)

Solution (Python):

def main():
    price, dilike_num = map(int, input().split())
    
    dislike_data = input().split()
    dislike_set = set(dislike_data)

    now_price = price
    while 1:
        now_price_set = set(list(str(now_price)))
        if len(now_price_set & dislike_set) == 0:
            break
        now_price += 1

    print(now_price)


if __name__ == '__main__':
    main()

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


while True:
    for n in str(N):
        if int(n) in D:
            N+=1
                
                
            break
    else:
        print(N)
        break

Solution (Python):


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

    n = N
    while True:
        k = str(n)
        ok = True
        for ki in k:
            if int(ki) in D:
                ok = False
        if ok:
            print(n)
            return
        n += 1



if __name__ == "__main__":
    solve()

Solution (Python):

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

d = input().split()

while True:
    n_list = list(set(list(str(n))))

    flag = 0
    for n_data in n_list:
        if n_data in d:
            flag = 1
            break


    if flag == 0:
        print(str(n))
        exit(0)
    else:
        n += 1

Solution (Python):
import sys
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    D=list(map(int,input().split()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        if len(str(N))==1:
            if p>=N:
                print(p)
                return
        else:
            for q in L:
                if len(str(N))==2:
                    pay=p*10+q
                    if pay>=N:
                        print(pay)
                        return
                else:
                    for r in L:
                        if len(str(N))==3:
                            pay=p*100+q*10+r
                            if pay>=N:
                                print(pay)
                                return
                        else:
                            for s in L:
                                pay=p*1000+q*100+r*10+s
                                if pay>=N:
                                    print(pay)
                                    return
    if L[0]==0:
        print(L[1]*10**len(str(N)))
    else:
        print("".join([str(L[0]) for _ in range(1+len(str(N)))]))
    return
            

if __name__=="__main__":
    main()

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

C = []
for k in range(10):
    if not k in D:
        C.append(k)

def num(a):
    if a!='' and (len(a) > n  or int(a)>=N):
        if int(a) >= N:
            return a
        return 114514
    d=1145141919
    for c in C:
        d =min(d, int(num(a + str(c))))
    return d

print(num(''))

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

n = N
while True:
    k = str(n)
    ok = True
    for ki in k:
        if int(ki) in D:
            ok = False
    if ok:
        print(n)
        break
    n += 1

Solution (Python):
def UnlikeNum(nums,price):
    for num in nums:
        if(str(num) in str(price)):
            return True
    
    return False

N, K = map(int,input().split())
D = list(map(int,input().split()))
while(UnlikeNum(D,N)):
    N+=1
print(N)

Solution (Python):

"""
Created on Fri Jul 26 04:39:44 2019

@author: matsui
"""

N,K=map(int,input().split())
D=input().split()
D=[int(D[i]) for i in range(K)]
    
        
for n in range(N,100000):
    a=n//10000
    b=n%10000//1000
    c=n%1000//100
    d=n%100//10
    e=n%10
    
    if a+b+c+d ==0:
        if e not in D :
            print(n)
            break
    if a+b+c ==0:
        if d not in D and e not in D :
            print(n)
            break
    elif a+b ==0:
        if c not in D and d not in D and e not in D :
            print(n)
            break
    elif a ==0:
        if b not in D and c not in D and d not in D and e not in D :
            print(n)
            break
    else:
        if a not in D and b not in D and c not in D and d not in D and e not in D :
            print(n)
            break

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
while True:
  for n in str(N):
    if int(n) in D:
      N+=1
      break
  else:
    print(N)
    break

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
while True:
    if set(map(int, list(str(n)))) & d == set():
        break
    else:
        n += 1
print(n)

Solution (Python):
import copy
import sys
import math

def main():
	n,k = map(int,input().split())
	d = list(map(str,input().split()))
	while True:
		s = str(n)
		flag  = True
		for i in s:
			if(i in d):
				flag = False
		if flag:
			print(n)
			sys.exit()
		else:
			n += 1


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Solution (Python):
import copy
import sys
import math

def main():
	n,k = map(int,input().split())
	d = list(map(str,input().split()))
	while True:
		s = str(n)
		flag  = True
		for i in s:
			if(i in d):
				flag = False
		if flag:
			print(n)
			sys.exit()
		else:
			n += 1


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

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


while True:
    for c in str(N):
        if c in lst_D:
            break
    else:
        print(N)
        break
    N += 1

Solution (Python):

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

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


now = N

while True:

    flag = True

    for d in D:

        if str(d) in str(now):
            flag = False
            break

    if flag:

        print (now)
        break

    else:

        now += 1

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,n*(10**7)):
    f=True
    l=set(str(i))
    for k in d:
        if k in l:
            f=False
    if f:
        print(i)
        exit()

Solution (Python):
n,k=map(int,input().split())
d=sorted(list(set(range(10))-set(map(int,input().split()))))
for i in range(n,100000):
    if set(map(int,str(i)))<=set(d):
        print(i)
        break

Solution (Python):
def check(num, dislike_list):
  for n in num:
    if n in dislike_list:
      return False
      break
  return True

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

while not check(str(N), dislike_num):
    N += 1

print(N)

Solution (Python):
import math

inl = input().split(' ')
length = len(inl[0])
n = int(inl[0])

hate = input().split(' ')

def checkhate(n,hate):
	n_str = str(n)
	for c in n_str:
		if c in hate:
			return False
	return True

while not checkhate(n,hate):
	n += 1

print(n)

Solution (Python):
n,k=map(int,input().split())
d=str(input().split())
result=n

count=0
while True:
  for j in range(len(str(result))):
    if str(result)[j] in d:
      count=0
      result+=1
      
      break
    else:
      count+=1
  if count==len(str(result)):
    break
print(result)

Solution (Python):
N, K = map(int, input().split())
L = input()
def func1(N):
  if len(str(N)) == 5:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L or str(N)[4] in L:
      return False
  elif len(str(N)) == 4:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L:
      return False
  elif len(str(N)) == 3:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L:
      return False
  elif len(str(N)) == 2:
    if str(N)[0] in L or str(N)[1] in L:
      return False
  elif len(str(N)) == 1:
    if str(N)[0] in L:
      return False
  else:
    return True
while func1(N) == False:
  N += 1
print(N)

Solution (Python):


from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    ANS = []
    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Solution (Python):



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

for i in range(n,100000):
    s = list(map(int,list(str(i))))
    for j in s:
        if j in d:
            break
    else:
        print(i)
        break

Solution (Python):
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]



flag = 0

for i in range(Num[0],10*Num[0]+1):
    for j in str(i):
        if int(j) in D:
            flag = 1
            break

    if flag == 0:
        print(i)
        break
    else:
        flag =0

Solution (Python):
n, _ = map(int, input().split())
dislike = input().split()
while True:
  flag = True
  for it in dislike:
    if it in str(n):
      flag = False
      break
  if flag:
    print(n)
    break
  n += 1

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

dec = []
for i in range(10) :
    if not i in D :
        dec.append(str(i))

i = N
while True :
    for j in str(i) :
        if not j in dec :
            break
    else :
        print(i)
        break
        
    i += 1

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
A = [i for i in range(10)]
A = set(A) - set(D)
A = list(A)
A.sort()
S = str(N)
s = ''
for i in range(len(S)):
    for j in range(len(A)):
        if int(S[i]) == A[j]:
            s += str(A[j])
            break
        if int(S[i]) < A[j]:
            s += str(A[j])
            for i in range(len(S)-i-1):
                s += str(A[0])
            break
    if len(s) == len(S):
        break
            
if len(s) == len(S):
    print(s)
else:
    if A[0] == 0:
        s = str(A[1])
        for i in range(len(S)):
            s += str(A[0])
    else:
        s = str(A[0])
        for i in range(len(S)):
            s += str(A[0])
    print(s)

Solution (Python):
def main():
    n, k = list(map(int, input().split()))
    d = input().split()
    pay = n
    while True:
        ok = True
        for d_i in d:
            if d_i in str(pay):
                ok = False
                break
        if ok:
            break
        else:
            pay += 1
    print(pay)

if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
pay=n
d=list(map(str,input().split()))
for i in range(n,10*n):
    sp=list(str(pay))
    if any(i in sp for i in d):
        pay=i
    else:
        break
print(pay)

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

payment = N
while True:
  count = 0
  for i in D:
    if i in str(payment):
      break
    else: 
      count += 1
  if count == len(D):
    print(payment)
    exit()
       
  payment += 1

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        next_d = 0
        if str(n)[i] == str(a[idx]):
            ans = str(a[idx]) + ans
        else:
            ans = str(a[idx]) + "".join([str(a[0]) for j in range(len(ans))])
if next_d == 1:
    idx = bisect.bisect_left(a, 1)
    if idx == len(a):
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        if str(a[idx]) == "1":
            ans = str(a[idx]) + ans
        else:
            ans = str(a[idx]) + "".join([str(a[0]) for j in range(len(ans))])
print(ans)

Solution (Python):
n,k = map(int,input().split())
d = list(map(str,input().split()))
d = set([str(x) for x in range(0,10)])-set(d)

while 1:
    can = set(list(str(n)))
    if all(x in d for x in can):
        print(n)
        break


    n+=1

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

for i in range(n, 100000) :
    si = str(i)
    for j in range(len(si)) :
        if si[j] in d :
            break
    else :
        print(i)
        break

Solution (Python):

def main():
    n, k = list(map(int, input().rstrip().split()))
    D = set(map(int, input().rstrip().split()))
    ans = n
    while any(int(i) in D for i in str(ans)):
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
L = [v for v in input().split()]

for n in range(N, 200000):
    s = list(str(n))
    
    f = False
    for c in s:
        if c in L:
            f = True
    if f:
        continue
            
    print("".join(s))
    exit()

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
dislike = []
for i in range(0, 10):
	dislike.append(False)
for i in range(0, K):
	dislike[D[i]] = True
while True:
	S = str(N)
	flag = True
	for i in range(0, len(S)):
		if dislike[int(S[i])]:
			flag = False
			break
	if flag:
		print(N)
		break
	N += 1

Solution (Python):
n,k=map(int,input().split())
dl=set(input().split())
ans=n
while True:
    for a in str(ans):
        if a in dl:
            break
    else:
        print(ans)
        break
    ans+=1

Solution (Python):
def main():
    n, k = input().split()
    d = set(input().split())

    while True:
        if len(set(n) & d)==0:
            print(n)
            break
        n = str(int(n) + 1)

if __name__=="__main__": main()

Solution (Python):
N, K = map(int, input().split())
Ds = set(map(int, input().split()))
nmbrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
nDs = nmbrs - Ds
payment = N
while True:
    payment_str = set(int(i) for i in str(payment))
    if payment_str.issubset(nDs) == True:
        print(payment)
        break
    else:
        payment += 1

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



obse_num = [0 for i in range(10)]
for i in range(K):
    obse_num[D[i]] = 1

pay_money = N

while 1:
    obse_flag = 1

    S = list(str(pay_money))
    for char in S:
        if obse_num[int(char)] == 1:
            obse_flag = 0
            break
    
    if obse_flag == 1:
        break
    
    pay_money += 1

print(pay_money)

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

f = []
for i in range(10):		f += [False]
for i in range(K):		f[d[i]] = True

x=N-1
l=True

while l:
	
	x+=1
	
	l=False
	b=x
	while b>0:
		if f[b%10]:
			l=True
			break
		b//=10

print(x)

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

while any(int(j) in D for j in str(N)):
    N+=1

print(N)

Solution (Python):
n,k=map(int,input().split())
d=set(input().split())
while True:
    if len(set(str(n))&d)>=1:
        n+=1
    else:
        print(n)
        break

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):
def good_number(D, n):
    if n < 10:
        return n % 10 not in D
    return n % 10 not in D and good_number(D, n // 10)

N, K = input().split()
digit_num = len(N)
N = int(N)
K = int(K)
D = list(map(int, input().split()))
ub = int(str(D[0]) * (digit_num + 1))
usable = []
for i in range(10):
    if i not in D:
        usable.append(i)


if usable[0] != 0:
    ub = int(str(usable[0]) * (digit_num + 1))
else:
    ub = int(str(usable[1]) + str("0") * digit_num)
    
for i in range(N, ub + 1):
    if good_number(D, i):
        print(i)
        break

Solution (Python):
N, K = input().split()
D = input().split()
E = [str(x) for x in range(10) if str(x) not in D]
n = len(N)

next_digit = [(str(d), 0) if str(d) not in D else None for d in range(10)]
for i in range(9, -1, -1):
    if next_digit[i] is None:
        j = (i + 1) % 10
        while next_digit[j] is None:
            j = (j + 1) % 10
        if i < j:
            next_digit[i] = next_digit[j]
        else:
            next_digit[i] = (next_digit[j][0], 1)

for i in range(n):
    if N[i] in D:
        carry = 0
        j = i
        reverse_mid = ""
        while j >= 0:
            d = N[j]
            if carry == 1:
                if d == '9':
                    d = '0'
                else:
                    d = chr(ord(d) + 1)
                    carry = 0
            nd, carry0 = next_digit[int(d)]
            reverse_mid += nd
            carry += carry0
            if carry == 0:
                break
            j -= 1
        if carry == 1:
            head = next_digit[1][0]
        else:
            head = N[:j]
        N = head + reverse_mid[::-1] + (E[0] * (n - 1 - i))
        break
print(N)

Solution (Python):
N, K = map(int, input().split())
D = input().split()
for n in range(N, 10 * N):
    if all(map(lambda c: c not in D, str(n))):
        print(n)
        break

Solution (Python):
n, k = map(int, input().split())
d=list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
for i in range(n,100000):
    flag=True
    for j in str(i):
        if int(j) in (d):
            flag = False
    if flag:
        print(i)
        break

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

for i in range(N, N*1000):
    A    = list(str(i))
    flag = True
    for a in A:
        if ( a in D ):
            flag = False
    if( flag == True):
        print(i)
        break

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

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list)+1)]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    print(x)
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            i += 1
            ans[j] = use[i]
        mapans = map(str,ans)
        x = int(''.join(mapans))

    print(x)

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

d = input().split()

while True:
  n_str = str(n)
  for ch in n_str:
    if ch in d:
      n += 1
      break
  else:
    print(n)
    break

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

d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i):
    I = str(i) 
    n = len(I) 
    for j in range(n): 
        if int(I[j]) in d: 
            pass
        else: 
            return False
    return True

for i in range(N, 10**5 + 1): 
    if check(i): 
        print (i) 
        exit()

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


d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): 
    I = str(i) 
    
    n = len(I) 
    for j in range(n): 
        
        if int(I[j]) in d: 
            pass
        else: 
            return False
    return True



for i in range(N, 10**5 + 1): 
    if check(i): 
        print (i) 
        exit()

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


d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i): 
    I = str(i) 
    
    n = len(I) 
    for j in range(n): 
        
        if int(I[j]) in d: 
            pass
        else: 
            return False
    return True



for i in range(N, 10**5 + 1): 
    if i >= N: 
        if check(i): 
            print (i) 
            exit()

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

d = []
for i in range(10):
    if i in D:
        pass
    else:
        d += [i]

def check(i):
    I = str(i)
    
    n = len(I)
    for j in range(n):
        
        if int(I[j]) in d:
            pass
        else:
            return False
    return True



for i in range(10**5 + 1):
    if i >= N:
        if check(i):
            print (i)
            exit()

Solution (Python):
p=input().rstrip().split(' ')
q=input().rstrip().split(' ')
l=[0]*10
for i in range(0,len(q)):
    l[int(q[i])]=1;
for i in range(int(p[0]),1000000000000):
    t=list(str(i))
    G=1;
    for j in range(0,len(t)):
        if l[int(t[j])]==1:
            G=0;
            break;
    if G==1:
        print(i)
        break;

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())

N,K = LI()
D = [str(i) for i in input().split()]


def main():
    ans = N
    while True:
        for i in range(K):
            
            if D[i] in list(str(ans)):
                
                ans += 1
                
                break
            if i == K - 1:
                return ans

print(main())

Solution (Python):
n, k = map(int, input().split())
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
            break
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1

Solution (Python):
n, k = map(int, input().split())
dlist = [s for s in input().split()]
ans = n
while True:
    blnOk = True
    for d in str(ans):
        if d in dlist:
            blnOk = False
    if blnOk:
        print(ans)
        exit()
    else:
        ans += 1

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

for i in range(N, 100000):
    flag = True
    for j in str(i):
        if j in D:
            flag = False
            break
    if flag:
        print(i)
        exit()

Solution (Python):
N,K = [int(x) for x in input().split()]
D = [x for x in input().split()]
ans = ''
for i in range(N,N+110000):
    flag = True
    for j in str(i):
        if(j in D):
            flag = False
            break
    if(flag):
        print(i)
        break

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()

Solution (Python):
n,k=map(int,input().split())
s=set(map(int,input().split()))
while len(set([int(c) for c in str(n)])&s)!=0:
	n+=1
print(n)

Solution (Python):
N,K=map(int,input().split())
D=list(input().split())
while N<100000:
    fr=False
    for j in D:
        if j in str(N):
            N+=1
            fr=True
            break
    if fr:
        continue
    else:
        print(N)
        exit()

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

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

cost = N
while True:
  for i in range(K):
    if str(D[i]) in str(N):
      break
  else:
    print(N)
    exit()
  N += 1

Solution (Python):
n, k = map(int,input().split())
d = list(map(str, input().split()))
def search(x):
    count = 0
    for i in d:
        if str(x).find(i) == -1:
            count += 1
    if len(d) == count:
        return True
while True:
   if search(n):
       break
   else:
       n += 1
print(n)

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

def search(x):
    count = 0
    for i in d:
        if str(x).find(i) == -1:
            count += 1
    if len(d) == count:
        return True
while True:
   if search(n):
       break
   else:
       n += 1
print(n)

Solution (Python):
[n,k]=[int(_) for _ in input().split()]
d=[int(_) for _ in input().split()]
dt=list({_ for _ in range(10)}-set(d))
def c(n,l):
  for _c in str(n):
    if int(_c) not in l: return False
  return True
while True:
  if c(n,dt): break
  n+=1
print(n)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LS()

  for i in range(n,100001):
    f=True
    for j in str(i):
      if j not in l:
        pass
      else:
        f=False
    if f:
      return i

print(main())

Solution (Python):
N,K = map(int,input().split())
D = set(int(x) for x in input().split())
safe = set(range(10)) - D

def test(N):
  return set(int(x) for x in str(N)) <= safe

def F(N):
  
  while N % 10:
    if test(N):
      return N
    N += 1
  
  x = F(N//10)
  y = min(safe)
  return 10*x + y

answer = F(N)
print(answer)