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):
amount, num = map(int, input().split())

hate_num_list = list(map(str, input().split()))

while(True):

    check = 0

    for digit in str(amount):

        if digit in hate_num_list:
            check += 1

    if check == 0:
        print(amount)
        break

    else:
        amount += 1

Solution (Python):
n,k = map(int,input().split())
d = list(map(int,input().split()))
for i in range(100001):
  nn = n+i
  cnt = 0
  for j in d:
    if str(j) in str(nn):
      break
    else:
      cnt += 1
  if cnt == len(d):
    print(nn)
    break

Solution (Python):
n, k = map(int, input().split())                            
array = list(map(int, input().split()))
 
def jadgesuruo():
    for i in range(k):
        if str(n).find(str(array[i])) >= 0:
            return False
            break
    return True
 
while True:
    if jadgesuruo():
        print(n)
        break
    else:
        n = n + 1

Solution (Python):
n, k = map(int, input().split())                            
array = list(map(int, input().split()))
 
def jadgesuruo():
    for i in range(k):
        if str(n).find(str(array[i])) >= 0:
            return False
            break
    return True
 
for i in range(10**5):
    if jadgesuruo():
        print(n)
        break
    else:
        n = n + 1

Solution (Python):
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]

n,k=INPUT()
A=INPUT()
accepted=[]
for i in range(10):
    if i not in A:
        accepted.append(i)
L=len(accepted)

ans=n
i=0
p=len(str(ans))
while(i<p):
    if int(str(ans)[i]) in accepted:
        
        i+=1
    else:
        ans+=1
        i=0
    p=len(str(ans))
print(ans)

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


for i in range(100001):
    if i >= int(N):
        ans=str(i)
        num=0
        for j in range(len(ans)):
            if int(ans[j]) not in listA:
                num += 1

            if num == len(ans):
                print(i)
                exit()

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
iscollect = False
while(True):
    for i in D:
        if str(i) in str(N):
            N += 1
            break
        else:
            if i == D[-1]:
                iscollect = True
                break
    if iscollect:
        break
print(N)

Solution (Python):
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
flag = True
ans = N
while flag:
    ans_nums = []
    x = ans
    while x>=1:
        ans_nums.append(x%10)
        x = (int)(x/10)
    
    a = list(set(ans_nums) & set(D))
    
    if len(a) == 0:
        flag = False
    else:
        ans += 1
print(ans)

Solution (Python):
n,k,*d=map(int,open(0).read().split())
c=0
for i in range(n*10):
  if n<=i:
    for j in str(i):
      if not int(j) in d:
        c+=1
      if c==len(str(i)):
        print(i)
        exit()
    c=0

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

for nn in range(n,10*n+1):
    if len(set(str(nn)) & d)==0:
        print(nn)
        break

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

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

L.sort()

i = N
while True:
    if set(list(str((i)))) <= set(L):
        print(i)
        break
    i += 1

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

Solution (Python):
N,K = map(int, input().split())
D = list(map(int, input().split()))
dt = [True] * 10
for d in D:
    dt[d] = False

def check(x):
    while x:
        if not dt[x%10]:
            return False
        x //= 10
    return True

for i in range(N, 10*N):
    if check(i):
        print(i)
        break

Solution (Python):
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

if n < 10:
    for i in ele:
        if i >= n:
            print(i)
            exit()

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y >= n:
            print(y)
            exit()
        else:
            que.append(y)

Solution (Python):
from collections import deque
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=deque([str(i) for i in range(10) if i not in a])
B=[str(i) for i in range(10) if i not in a]
while True:
  s=A.popleft()
  if int(s)>=N:
    print(s)
    exit()
  A.extend([s+i for i in B])

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

ans=N

for price in range(N,10**5+1):
    s=str(price)
    flag=True
    for i in range(len(s)):
        if int(s[i]) in D:
            flag=False
    if flag:
        ans=price
        break

print(ans)

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

i = N
while True:
  flg = True
  for j in str(i):
    if int(j) in D:
      flg = False
      break

  if flg == True:
    print(i)
    exit()

  i += 1

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

flag = False

for i in range(N,100000):
    N = i
    while i > 0:
        flag = True
        if i%10 in D:
            flag = False
            break
        else:
            i //=10

    if flag == True:
        print(N)
        break

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

for i in range(N, 1000000):
    if len(list(set(D) & set(str(i)))) == 0:
        print(i)
        break

Solution (Python):
a, b = map(int, input('').split(' '))
c = input('').split(' ')
for i in range(a, 1000000):
	for j in range(len(str(i))):
		if str(i)[j] in c:
			break
	else:
		print(i)
		break

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
d ^= {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

while True:
    if d >= set(map(int, list(str(n)))):
        print(n)
        break
    n += 1

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
d ^= {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

while True:
    if d >= set(map(int, list(str(n)))):
        print(n)
        break
    n += 1

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



for ans in range(N, 10 * N + 1):
    s = str(ans)
    flag = True
    for ch in s:
        if int(ch) in setD:
            flag = False
            break
    if flag:
        print(ans)
        exit()

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 



from collections import deque

N, K = mi()
D = list(map(str, sys.stdin.readline().split()))

for num in range(N, N*10+1):
    flag = 1
    s = str(num)
    for i in range(K):
        if s.count(D[i]):
            flag = 0
            break
    if flag:
        print(num)
        exit()

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 



from collections import deque

N, K = mi()
D = list(map(str, sys.stdin.readline().split()))

for num in range(N, N*10+1):
    flag = 1
    s = str(num)
    for i in range(K):
        if s.count(D[i]):
            flag = 0
            break
    if flag:
        print(num)
        exit()

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 


from collections import deque

N, K = mi()
D = li()

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

if r[0]==0:
    que = deque(r[1:])
    
else:
    que = deque(r)
    

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    i += 1

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 


from collections import deque

N, K = mi()
D = li()

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

if r[0]==0:
    que = deque(r[1:])
    
else:
    que = deque(r)
    

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    i += 1

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 




N, K = mi()
D = li()

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

if r[0]==0:
    
    que = r[:][1:]
else:
    
    que = r[:]

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    
        
    i += 1

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 


from collections import deque

N, K = mi()
D = li()

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

if r[0]==0:
    que = deque(r[1:])
else:
    que = deque(r)

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)


print(que[ind])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect 


from collections import deque

N, K = mi()
D = li()

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

if r[0]==0:
    que = deque(r[1:])
else:
    que = deque(r)

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)


print(que[ind])

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = N
while True:
  tmp = n
  ng = False
  while tmp > 0:
    ng = ng or tmp%10 in D
    tmp //= 10
  if not ng:
    break
  n += 1
print(n)

Solution (Python):
n, k = map(int, input().split())
ddd = set(input().split())
while not ddd.isdisjoint(str(n)):
    n += 1
print(n)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	
	n , k = IN()
	el=set(IN())
	for i in range(n, 1000000):
		is_ok=True
		for v in list(str(i)):
			
			
			if int(v) in el:
				is_ok=False
				break
		if is_ok:
			return i
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def next(v, cu):
	for i in cu:
		if i > v:
			return i
	else:
		return -1

def main():
	n, k = IN()
	al = list(IN())
	cu=[]
	for i in range(10):
		if i not in al:
			cu.append(i)
	non_zero_min = cu[0] if cu[0] > 0 else cu[1]
	is_cu0_is_0 = cu[0]==0
	
	if n < 10:
		if n in cu:
			return n
		if n > cu[-1]:
			return non_zero_min*10+cu[0]
	
	kiriage=False
	ret=[]
	for i, v in enumerate(str(n)):
		if kiriage:
			ret.append(cu[0])
		elif int(v) in cu:
			ret.append(v)
		else:
			kiriage=True
			n = next(int(v),cu)
			if n == -1:
				if i != 0:
					ret.append(cu[0])
				else:
					ret.append(str(non_zero_min)+str(cu[0]))
				
				for ic in range(i-1,-1,-1):
					
					t=ret[ic]
					nt = next(int(t),cu)
					if nt != -1:
						
						ret[ic]=nt
						break
					elif nt == -1 and ic == 0:
						ret[ic]=str(non_zero_min)+str(cu[0])
						
					else:
						ret[ic]=cu[0]
			else:
				ret.append(n)
	return ''.join([str(r) for r in ret])
			
			
			
			
			
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()

q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    

    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        
        
        
        b += str(d)
        q.append(b)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, K = MAP()
D = LIST()
 
q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        if len(b) == 0:
            if d == 0:
                continue
        b += str(d)
        q.append(b)

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

Solution (Python):
N, K = map(int, input().split())
dislike = list(map(str, input().split()))
num = ["0","1","2","3","4","5","6","7","8","9"]
can_use = set(num) - set(dislike)

while not set(list(str(N))) <= can_use:
    N += 1

print(N)

Solution (Python):
n,k = map(int,input().split())
d = list(input().split())
ans = n
while True:
    flag = False
    for i in d:
        if flag :break
        if i in str(ans):
            ans += 1
            flag = True
    if flag:continue
    break
print(ans)

Solution (Python):
def resolve():
	n, k, = map(int, input().split())
	ok = [str(i) for i in range(10)]
	for i in input().split():
		if i in ok:
			ok.remove(i)

	while True:
		again = False
		for i in str(n):
			if not i in ok:
				again = True
				n += 1
				break
		if not again:
			break
	print(n)
resolve()

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(0,K):
    A.remove(D[i])
A=sorted(A)
B=A
B.append(0)
ans=0
M=str(N)
L=len(M)
if A[0]==0:
    ans+=111111*A[1]
else:
    ans+=111111*A[0]

if L==5:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        for y in range(0,10-K):
                            if ans>=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]>=N:
                                ans=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]
elif L==4:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        if ans>=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]>=N:
                            ans=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]
elif L==3:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    if ans>=10*(100*B[q]+10*A[w]+A[e])+A[r]>=N:
                        ans=10*(100*B[q]+10*A[w]+A[e])+A[r]
elif L==2:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                if ans>=100*B[q]+10*A[w]+A[e]>=N:
                    ans=100*B[q]+10*A[w]+A[e]
else:
    for q in range(0,11-K):
        for w in range(0,10-K):
            if ans>=10*B[q]+A[w]>=N:
                ans=10*B[q]+A[w]

print(ans)

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

def checkiroha(a):
    a1 = str(a)
    for i in range(len(a1)):
        if (a1[i] in si):
            return 'F'
        elif (i == (len(a1)-1)):
            return 'T'
        else:
            continue

while (checkiroha(n) == 'F'):
    n = n+1
else:
    print(n)

Solution (Python):
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

N, K = ints()
D = [False]*10

for d in ints():
    D[d] = True

while any([D[int(d)] for d in str(N)]):
    N+=1

print(N)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Solution (Python):
def function1(m, set1):
  set2 = set(str(m))
  if len(set1 & set2) > 0:
    return False
  else:
    return True
def function(n, set1):
  m = n
  while not function1(m, set1):
    m += 1
  return m

line1 = input().split()
n = int(line1[0])
k = int(line1[1])
list1 = input().split()
set1 = set(list1)

print(function(n, set1))

Solution (Python):
N, K = map(int, input().split())
D = set(input().split())
 
for i in range(N,10**5):
    l = set(list(str(i)))
    if l & D:
        continue
    print(i)
    break

Solution (Python):
def intersection(lst1, lst2): 
    lst3 = [value for value in lst1 if value in lst2] 
    return lst3 

n,k=map(int,input().split())
a=list(map(str,input().split()))
while(1):
    x=list(str(n))
    check=True
    if len(intersection(x,a))==0:
        print(n)
        break
    n+=1

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

i = N
while True:
  flg = True
  for j in str(i):
    if int(j) in D:
      flg = False
      break

  if flg == True:
    print(i)
    exit()

  i += 1

Solution (Python):
def check(n):
    if set(list(map(int, str(n)))) & D:
        return 1
    else:
        return 0


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

surplus = 0
while check(N + surplus):
    surplus += 1
print(N + surplus)

Solution (Python):
n, k=map(int, input().split())
d = list(input().split())
i=n
while True:
    count = 0
    for j in range(k):
        if d[j] in str(i):
            count += 1
    if count == 0:
        print(i)
        break
    else:
        i += 1

Solution (Python):


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

k = input()
s = [int(j) for j in k.split(" ")]
valIn = 0

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

def irohacheck(n):
	global valIn
	valIn = 0
	
	num = digit(n)
	
	for i in range(len(num)):
		if s.count(num[i])>0:
			valIn+=1

irohacheck(N)
while(valIn != 0):
	N += 1
	irohacheck(N)
print(N)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
d = list(input().split())
for check in range(n, 10 ** 5):
    flag = True
    for i in str(check):
        if i in d:
            flag = False
            break
    if flag:
        print(check)
        exit()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

    for i in range(n, 10**8):
        s = str(i)
        for j in a:
            if j in s:
                break
        else:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Solution (Python):

def resolve():
    N, K = map(int, input().split())
    D = set(input().split())
    while True:
        if D & set(str(N)):
            N += 1
            continue
        print(N)
        return


if __name__ == "__main__":
    resolve()

Solution (Python):
def is_include(n,D):
  for c in str(n):
    for d in D:
      if d == c:
        return True
  else:
    return False

n,k = map(int,input().split())
D = list(map(str,input().split()))
for i in range(n,n*10):  
  if is_include(i,D) == False:
    print(i)
    break

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

nmax=100000

for nn in range(n,nmax):
    ns=list(str(nn))
    yn="yes"
    for nsi in ns:

        if int(nsi) in d:
            yn="no"
            break
    if yn=="no":
        continue
    else:
        break
if yn=="yes":
    print(nn)

Solution (Python):
import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)

def main(d):
    res = ''
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    j = str(j)
                    if j in d:
                        res += j
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l
    print(res)

if __name__ ==  '__main__':
    main(d)

Solution (Python):
import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)

def main(d):
    res = ''
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    if str(j) in d:
                        res += str(j)
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l
    print(res)

if __name__ ==  '__main__':
    main(d)

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

Solution (Python):

import collections


def solve(n, k, digits):
    digitsNotAvailable = set(digits)

    ans = n

    while True:
        temp = ans
        possible = True

        while temp:
            digit = temp % 10

            if digit in digitsNotAvailable:
                possible = False
                break

            temp //= 10

        if possible:
            return ans

        ans += 1

    return None


[n, k] = list(map(int, input().strip().split()))
digits = list(map(int, input().strip().split()))

print(solve(n, k, digits))

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

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

kagu = []

for i in range(10):
    if i in t:
        continue
    kagu.append(str(i))

ans = 1000000000000

for i in kagu:
    if i == '0':
        continue
    if n<=int(i):
        print(i)
        exit()
    memo = [i]
    while int(memo[-1])< n:
        a = memo.pop(0)
        for j in kagu:
            goukei = a+j
            memo.append(goukei)
            if n<=int(goukei):
                ans = min(ans,int(goukei))
                break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    def main():
        
        N,K=map(int,input().split())
        D=set(map(int,input().split()))

        L={i for i in range(10)}
        U=L-D
        while True:

            sn = str(N)
            ln = len(sn)

            for i in range(ln):
                if int(sn[i]) not in U:
                    N+=1
                    break
                elif i==ln-1:
                    return int(N)
    print(main())



resolve()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
d = LI()
for i in range(n,10*n+1):
    s = Counter(list(map(int,list(str(i)))))
    for j in d:
        if s[j] > 0:
            break
    else:
        print(i)
        quit()

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  n,k = readInts()
  D = input().split()
  
  
  
  
  
  while set(str(n)) & set(D):
    n += 1
  print(n)
  
if __name__ == '__main__':
  main()

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

i = N
while True:
    
    b = list(str(i))
    b = set(b)
    
    c = b&D
    
    if len(c)>0 :
        i += 1
        continue
    else:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
d = list(input().split())
dis = False
while True:
  a = str(n)
  hate = False
  for x in a:
    for y in d:
      if x == y:
        hate = True
        break
    if hate == True:
      break
  if hate == True:
    n += 1
  else:
    break
  if n > 100000:
    break
print(n)