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



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Runtime Error

Solution code:
N, K = map(str, input().split())
N = ''.join(list(reversed(N)))
num_ls = [i for i in range(10)]
ls = map(int, input().split())
dif = list(set(num_ls) - set(ls))
dif.sort()
ans = '' 

for i in N:
    tmp = min(filter(lambda x: int(i) <= x, dif))
    if tmp == None:
        tmp=min(dif)
    ans = ans + str(tmp)

print(''.join(list(reversed(ans))))

Submission status: Runtime Error

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

line1 = input().split()
n = int(line1[0])
k = int(line1[1])
list1 = []
for i in range(k):
  list1.append(int(input()))
set1 = set(list1)

print(function(n, set1))

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import math
readline = sys.stdin.buffer.readline

#N,K = map(int, readline().split())
N = list(input())
#print(N)
K=int(N[len(N)-1])
N.remove(' ')
N.remove(N[len(N)-1])
#print(N)
A = list(input().split())

#print(N,K)
#print(A)

Number=['1','2' ,'3', '4', '5', '6', '7', '8', '9','0']
#'''
for i in range(0,K):
    
    if A[i]== '1':
        Number.remove('1')
    elif A[i]== '2':
        Number.remove('2')
    elif A[i]== '3':
        Number.remove('3')
    elif A[i]== '4':
        Number.remove('4')
    elif A[i]== '5':
        Number.remove('5')
    elif A[i]== '6':
        Number.remove('6')
    elif A[i]== '7':
        Number.remove('7')
    elif A[i]== '8':
        Number.remove('8')
    elif A[i]== '9':
        Number.remove('9')
    elif A[i]== '0':
        Number.remove('0')
#'''    
#print(N,K)
#print(A)

#print(Number,'Number')

Answer=[]
#print(N,'N')
for i in range(0,len(Number)):
    for j in range (0,len(N)):
        if int(Number[i])>=int(N[j]):
            Answer.append(Number[i])
            #print(min(Number[i]))


Answer1=[]
for i in range (0,len(N)):
    Answer1.append(Answer[i])
    
#Answer1.reverse()    
Answer1 = ''.join(Answer1)


print(Answer1)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import math
readline = sys.stdin.buffer.readline

#N,K = map(int, readline().split())
N = list(input())
#print(N)
K=int(N[len(N)-1])
N.remove(' ')
N.remove(N[len(N)-1])
#print(N)
A = list(input().split())

#print(N,K)
#print(A)

Number=['1','2' ,'3', '4', '5', '6', '7', '8', '9','0']
#'''
for i in range(0,K):
    
    if A[i]== '1':
        Number.remove('1')
    elif A[i]== '2':
        Number.remove('2')
    elif A[i]== '3':
        Number.remove('3')
    elif A[i]== '4':
        Number.remove('4')
    elif A[i]== '5':
        Number.remove('5')
    elif A[i]== '6':
        Number.remove('6')
    elif A[i]== '7':
        Number.remove('7')
    elif A[i]== '8':
        Number.remove('8')
    elif A[i]== '9':
        Number.remove('9')
    elif A[i]== '0':
        Number.remove('0')
#'''    
#print(N,K)
#print(A)

#print(Number,'Number')

Answer=[]
print(N,'N')
for i in range(0,len(Number)):
    for j in range (0,len(N)):
        if int(Number[i])>=int(N[j]):
            Answer.append(Number[i])
            #print(min(Number[i]))


Answer1=[]
for i in range (0,len(N)):
    Answer1.append(Answer[i])
    
#Answer1.reverse()    
Answer1 = ''.join(Answer1)


print(Answer1)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
import math
readline = sys.stdin.buffer.readline

#N,K = map(int, readline().split())
N = list(input())
#print(N)
K=int(N[len(N)-1])
N.remove(' ')
N.remove(N[len(N)-1])
#print(N)
A = list(input().split())

#print(N,K)
#print(A)

Number=['1','2' ,'3', '4', '5', '6', '7', '8', '9','0']
#'''
for i in range(0,K):
    
    if A[i]== '1':
        Number.remove('1')
    elif A[i]== '2':
        Number.remove('2')
    elif A[i]== '3':
        Number.remove('3')
    elif A[i]== '4':
        Number.remove('4')
    elif A[i]== '5':
        Number.remove('5')
    elif A[i]== '6':
        Number.remove('6')
    elif A[i]== '7':
        Number.remove('7')
    elif A[i]== '8':
        Number.remove('8')
    elif A[i]== '9':
        Number.remove('9')
    elif A[i]== '0':
        Number.remove('0')
#'''    
#print(N,K)
#print(A)

#print(Number,'Number')

Answer=[]
for i in range(0,len(Number)):
    for j in range (0,len(N)):
        if int(Number[i])>=int(N[j]):
            Answer.append(min(Number[i]))
            #print(min(Number[i]))
#print(N,'N')

Answer1=[]
for i in range (-len(N),0):
    Answer1.append(Answer[i])
    
Answer1 = ''.join(Answer1)

print(Answer1)

Submission status: Runtime Error

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

sN = str(N)
L = len(sN)
ans = ""

for i in range(1,L):
    if sN[i] in can_use:
        ans += sN[i]
    else:
        ans += min(can_use)

if sN[0] in can_use:
    ans += sN[0]
else:
    if can_use[0] == "0":
        ans = can_use[1] + ans
    else:
        ans = can_use[0] + ans

if int(ans) < N:
    if can_use[0] != "0":
        ans = ans + can_use[1]
    else:
        ans = ans + can_use[0]

print(ans)

Submission status: Runtime Error

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

sN = str(N)
L = len(sN)
ans = ""

if sN[0] in can_use:
    ans += sN[0]
else:
    if can_use[0] == "0":
        ans += can_use[1]
    else:
        ans += can_use[0]

for i in range(1,L):
    if sN[i] in can_use:
        ans += sN[i]
    else:
        ans += min(can_use)

if int(ans) < N:
    if can_use[0] != "0":
        ans = ans + can_use[1]
    else:
        ans = ans + can_use[0]

print(ans)

Submission status: Runtime Error

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

l=list()
for i in range(10):
    l.append(i)

l=list(set(d) ^ set(l))
lFirst=list(set(l) ^ set([0]))

nList=list(map(int, list(str(n))))


answer=list()
flag=False

for i in lFirst:
    if nList[0]<i:
        answer.append(i)
        for i in range(1,len(nList)):
            answer.append(l[0])
        flag=True
    elif nList[0]==i:
        answer.append(i)
        break

if False==flag:
    for i in range(1,len(nList)):
        for j in l:
            if nList[i]<=j:
                answer.append(j)
                break

ans=''
for i in answer:
    ans+=str(i)

print(int(ans))

Submission status: Runtime Error

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

n_str = str(n)
# print(n_str)

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

# print(l)
ans_list = []

for i in range(len(n_str)):
  if int(n_str[i]) in l:
    ans_list.append(n_str[i])
  elif int(n_str[i]) < l[-1]:
    for j in range(len(l)):
      if l[j] > int(n_str[i]):
        ans_list.append(l[j])
        break
    for k in range(i+1, len(n_str)):
      ans_list.append(l[0])
    break

# print(ans_list)

ans = ''
for i in range(len(ans_list)):
  ans += str(ans_list[i])

print(int(ans))

Submission status: Runtime Error

Solution code:
n,_=map(int,input().split())
s=set(input())
while s&set(str(n)): n+=1
print(n

Submission status: Runtime Error

Solution code:
    N = int(input().split(' ')[0])
    D = set(input())
    while len(set(str(N))&D)!=0:
        N += 1
    print(N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
for
ans = ""
for n in str(N):
  a = 0
  while True:
    if int(n) in D:
      n = int(n) + 1
      a = int(n)+1
    else:
      a = int(n)
      ans += str(a)
      break

print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
L = set(map(int, input().split()))

A = set(i for i in range(10))
B = sorted(list(A - L))

N_digit = len(str(N))

pay = ""

for i in str(N):
    for b in B:
        if b >= int(i):
            pay += str(b)
            break
        else:
            continue
if int(pay):
    print(int(pay))
else:
    if int(min(B)) == 0:
        C = B - set(0)
        pay = str(min(C))
        for i in range(digit_N):
            pay += "0"
        print(int(pay))
    else:
        pay = str(min(C))
        for i in range(digt_N):
            pay += str(min(C))
        print(int(pay))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
L = set(map(int, input().split()))

A = set(i for i in range(10))
B = sorted(list(A - L))

N_digit = len(str(N))
pay = ""

for i in str(N):
    for b in B:
        if b >= int(i):
            pay += str(b)
            break
        else:
            continue

print(int(pay))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
# L = set(input() for i in range(K))
L = set(map(int, input().split()))
# 差集合→list
A = set(i for i in range(10))
B = sorted(list(A - L))

N_digit = len(str(N))
pay = ""

for i in str(N):
    for b in B:
        if b >= int(i):
            pay += str(b)
            break
        else:
            continue

print(int(pay))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
N=list(str(n))
for i in range(len(N)):
  N[i]=int(N[i])
for i in range(n,n*10+1):
  if not N.isdisjoint(d):
    print(i)
    exit()

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
Ds = list(map(int, input().split()))

able = []
for i in range(10):
    if i in Ds:continue
    able.append(i)
# print(able)

sN = str(N)
n = len(sN)
m = able[0] #最小


if int(sN[0]) > max(able):
    if m == 0:
        ans = str(able[1]) + str(able[0]) * n
    else:
        ans = str(able[0]) * (n+1)
    print(ans)
    exit()
prev = -1
flg = True #確定していない
ans = ""
for i,s in enumerate(sN):
    flg2 = False
    if flg:
        for j,a in enumerate(able):
            if int(s) < a:
                ans += str(a)
                flg = False
                flg2 = True
                break
            if int(s) == a:
                ans += str(a)
                flg = True
                flg2 = True
                break
        if not flg2:
            ans = ans[:-1]
            ans += str(able[prev+1]) + str(m)
            flg = False
    else:
        ans += str(m)    
    prev = j
    # print(ans)

print(ans)
"""
1333 8
0 3 4 5 6 7 8 9
"""

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
Ds = list(map(int, input().split()))

able = []
for i in range(10):
    if i in Ds:continue
    able.append(i)
# print(able)

sN = str(N)
n = len(sN)
m = able[0] #最小


if int(sN[0]) > max(able):
    if m == 0:
        ans = str(able[1]) + str(able[0]) * n
    else:
        ans = str(able[0]) * (n+1)
    print(ans)
    exit()
prev = -1
flg = True #確定していない
ans = ""
for i,s in enumerate(sN):
    flg2 = False
    if flg:
        for j,a in enumerate(able):
            if int(s) < a:
                ans += str(a)
                flg = False
                flg2 = True
                break
            if int(s) == a:
                ans += str(a)
                flg = True
                flg2 = True
                break
        if not flg2:
            ans = ans[:-1]
            ans += str(able[prev+1]) + str(m)
            flg = True
    else:
        ans += str(m)    
    prev = j

print(ans)

Submission status: Runtime Error

Solution code:
N,K = list(map(str, input().split()))
D = sorted(input().split())
W = []
P = ""

for i in range(10):
    if str(i) not in D:
        W.append(str(i))

for i in range(len(N)):
    for j in range(len(W)):
        if N[i] <= W[j]:
            P += W[j]
            break

print(int(P))

Submission status: Runtime Error

Solution code:
n, k = input().split()
d = input().split()
valid = [i for i in range(10) if str(i) not in d]
ans = ''

if valid[-1] < int(n[0]):
    if valid[0] == 0:
        ans += str(valid[1])
    else:
        ans += str(valid[0])
    ans += str(valid[0]) * len(n)
else:
    for i, s in enumerate(n):
        if i > 0 and ans[i-1] > n[i-1]:
            ans += str(valid[0]) * (len(n)-i)
            break

        for k in valid:
            if k >= int(s):
                ans += str(k)
                break
print(ans)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(input())
restrict = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i):
	global restrict
	if not restrict:
		return min_number
	for s in range(10):
		if (str(s) not in d_ng_list) and str(s) >= n_price[i]:
			if s > int(n_price[i]):
				restrict = False
			return str(s)

def rec_cal_pay(answer, i, restrict):
	if i == n_length-1:
		answer += find_number(i)
		print(answer)
		return
	else:
		c = find_number(i)
		rec_cal_pay(answer+c, i+1, restrict)
rec_cal_pay(answer, 0, restrict)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(map(str,input().split()))
restricted = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i,restricted):
	if not restricted:
		return min_number
	for s in range(10):
		if str(s) not in d_ng_list and str(s) >= n_price[i]:
			if str(s) > n_price[i]:
				restricted = False
			return str(s)	

def rec_cal_pay(answer, i):
	if i == n_length-1:
		answer += find_number(i,restricted)
		print(answer)
		return
	else:
		c = find_number(i,restricted)
		rec_cal_pay(answer+c,i+1)
rec_cal_pay(answer, 0)

Submission status: Runtime Error

Solution code:
n_price,k = map(str,input().split())
k = int(k)
n_length = len(n_price)
d_ng_list = list(map(str,input().split()))
restricted = True
answer = ""
for s in range(10):
	if str(s) not in d_ng_list:
		min_number = str(s)
		break

def find_number(i,restricted):
	if not restricted:
		return min_number
	for s in range(10):
		if str(s) not in d_ng_list and str(s) >= n_price[i]:
			if str(s) > n_price[i]:
				restricted = False
			return str(s)	

def rec_cal_pay(answer, i):
	if i == n_length-1:
		answer += find_number(i,restricted)
		print(answer)
		return
	else:
		c = find_number(i,restricted)
		rec_cal_pay(answer+c,i+1)
rec_cal_pay(answer, 0)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
D = list(map(int,input().split()))
while True:
  dis = False
  for d in D:
    if d in str(n):
      dis = True
      break
  if not dis:
    break
  n += 1
print(n)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
D = list(input())
for i in range(N, 10000):
    M = list(str(i))
    if all([M[j] not in D for j in range(len(M))]):
        ans = int("".join(M))
        break
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,(input().split()))
li=[]
for i in range(K):
    li.append(int(input()))
for j in range(N,10000):
    k=0
    for t in str(j):
        if int(t) in li:
            k=1
            break
    else:
        if k==0:
            print(j)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
for i in range(n, 100000):
    s = list(str(i))
    flg = 0
    for j in s:
        if j in d:
            flg = 1
            break
    if flg == 0:
        print("".join(s))
        break

Submission status: Runtime Error

Solution code:
#abc 042 c
def dfs(i,s):
    if i==n_keta:
        if s>=n:
            kouho.append(s)
        return 0
    for j in range(len(like)):
        dfs(i+1,s+like[j])
    return 0

n,k=input().split()
d=list(map(int,input().split()))
like=[]
for i in range(10):
    if i not in d:
        like.append(str(i))
kouho=[]
n_keta=len(n)
dfs(0,"")
if not kouho:
    n_keta+=1
    dfs(0,"")
print(min(kouho))

Submission status: Runtime Error

Solution code:
#abc 042 c
def dfs(i,s):
    if i==n_keta:
        if s>=n:
            kouho.append(s)
        return 0
    for j in range(len(like)):
        dfs(i+1,s+like[j])
    return 0




n,k=input().split()
d=list(map(int,input().split()))
like=[]
for i in range(10):
    if i not in d:
        like.append(str(i))
kouho=[]
n_keta=len(n)
dfs(0,"")
print(min(kouho))

Submission status: Runtime Error

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


n,k = map(int,input().strip().split())
d = list(input().split())
for x in range(n,100000):
    for y in d:
        if y in str(x):
            break
    else:
        print(x)
        break

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = list(map(int, input().split()))
Li = list(n)
while len(set(Li)&set(li)):
  n += 1
  Li = list(n)
else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = list(map(int, input().split()))
Li = list(n)
while set(Li)&set(li):
  n += 1
  Li = list(n)
else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
for i in range(k):
  li.append(int(input()))
else:
  Li = list(n)
  while not len(set(li)&set(Li)) == 0:
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
for i in range(k):
  li.append(int(input()))
else:
  Li = list(n)
  while not len(set(li)&set(Li)):
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(n)
  while not len(set(li)&set(Li)):
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(n)
  while not set(li)&set(Li) == set():
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(n)
  while not set(li)&set(Li) == {}:
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(n)
  while li&Li:
    n += 1
    Li = list(n)
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(str(n))
  while li&Li:
    n += 1
    Li = list(str(n))
  else: print("".join(Li))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)+1):
        stack.append(i+s)

print(min(ans))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)):
        stack.append(i+s)
print(min(ans))

Submission status: Runtime Error

Solution code:
N,K=input().split()
D=input().split()

while True:
    for s in D:
        if N.count(s)!=0:
            frag=1

        else:
            pass
    if frag==1:
        a=int(N)+1
        N=str(a)
        frag=0

    else:
        break

print(N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
N_str = str(N)
nl = list(N_str)
D_str = []
for i in D:
    D_str.append(str(i))

d_in_n = False
for i in nl:
    if not i in D_str:
      continue
    else:
      d_in_n = True
      break
if d_in_n == False:
    print(N)
else:
    while len(nl) < 4:
        nl.insert(0,'0')
    L = []
    for i in range(10):
        if not i in D:
            L.append(i)

    SUB = []
    if nl[0] == '0' and nl[1] == '0' and nl[2] == '0':
        for l in L:
            N2 = l
            sub = N2 - N
            if N2 - N > 0:
                SUB.append(N2) 
    elif nl[0] == '0' and nl[1] == '0':
        for k in L:
            for l in L:
                N2 = 10*k + l
                sub = N2 - N
                if N2 - N > 0:
                    SUB.append(N2)
    elif nl[0] == '0':
        for j in L:
            for k in L:
                for l in L:
                    N2 = 100*j + 10*k + l
                    sub = N2 - N
                    if N2 - N > 0:
                        SUB.append(N2)
    else:
        for i in L:
            for j in L:
                for k in L:
                    for l in L:
                        N2 = 1000*i + 100*j + 10*k + l
                        sub = N2 - N
                        if N2 - N > 0:
                            SUB.append(N2)
    SUB_s = sorted(SUB)
    print(SUB_s[0])

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
N_str = str(N)
nl = list(N_str)
D_str = []
for i in D:
    D_str.append(str(i))

d_in_n = False
for i in nl:
    if not i in D_str:
      continue
    else:
      d_in_n = True
      break
if d_in_n == False:
    print(N)
else:
    L = []
    for i in range(10):
        if not i in D:
            L.append(i)
    SUB = []
    for i in L:
        for j in L:
            for k in L:
                for l in L:
                    N2 = 1000*i + 100*j + 10*k + l
                    sub = N2 - N
                    if N2 - N > 0:
                        SUB.append(N2)
    SUB_s = sorted(SUB)
    print(SUB_s[0])

Submission status: Runtime Error

Solution code:

N, K = map(int, input().split())
D = list(map(int, input().split()))
N_str = str(N)
nl = list(N_str)
D_str = []
for i in D:
    D_str.append(str(i))

d_in_n = False
for i in nl:
    if not i in D_str:
      continue
    else:
      d_in_n = True
      break
if d_in_n == False:
    print(N)
else:
    L = []
    for i in range(10):
        if not i in D:
            L.append(i)
    SUB = []
    for i in L:
        for j in L:
            for k in L:
                for l in L:
                    N2 = 1000*i + 100*j + 10*k + l
                    sub = N2 - N
                    if N2 - N > 0:
                        SUB.append(N2 - N)
    SUB_s = sorted(SUB)
    print(SUB_s[0] + N)

Submission status: Runtime Error

Solution code:
N,K=input().split()
dis=list()
dis=input().split()

while True:
    for c in dis:
        if N.count(c)!=0:
            frag=1
        else:
            pass

    if frag==1:
        N=int(N)+1
        N=str(N)
        frag=0
    else:
        break

print(N)

Submission status: Runtime Error

Solution code:
N,K=input().split()
dis=list(K)
dis=input().split()

while True:
    for c in dis:
        if N.count(c)!=0:
            frag=1
        else:
            pass

    if frag==1:
        N=int(N)+1
        N=str(N)
        frag=0
    else:
        break

print(N)

Submission status: Runtime Error

Solution code:
N,K=input().split()
dis=list(K)
dis=input().split()

while True:
    for c in dis:
        if N.count(c)!=0:
            frag=1
        else:
            pass

    if frag==1:
        N=int(N)+1
        N=str(N)
        frag=0
    else:
        break

print(N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = sorted(list(num_set.difference(set(D))))

if (list(set(D)&set(N_list)) == []):
    print(N)
else:
    if '0' in diff_list:
        n_list = [diff_list[1]] + ['0']*len(N_list)
    else:
        n_list = [diff_list[0]]*len(N_list+1)
    str_n = ''
    for i in n_list:
        str_n += str(i)
    new_n = int(str_n)+1
    for ii in range(N, new_n):
        if list(set(list(str(ii)))&set(D)) == []:
            print(ii)
            break

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
a = 0
for i in range(n, 10000):
  if checknum(i, d):
    a = i
    break
print(a)

def checknum(n, d):
  for s in str(n):
    if d.count(int(s)) > 0:
      return False
  return True

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/use/bin/env python3

(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

like = []

ans = n

while (1):

    c = True
    for ii in range(0, 4):
        b = b // 10
        d = b % 10

        if b == 0:
            break

        if d in a:
            c = False
            break

    if (c):
        ans = n
        break
    n += 1

print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
list_num = [input() for i in range(k)]
price = n
while True :
    i = 0
    for i in range(len(str(price))) :
        if str(price)[i] in list_num :
            price += 1
            break
    else :
        print(price)
        break

Submission status: Runtime Error

Solution code:
from functools import lru_cache
N, K = map(int, input().split())
D = input().split()

O = []
for c in "0123456789":
    if c not in D:
        O.append(c)

# N = 523
# D = 2 3

@lru_cache()
def func(s, i, over):
    if i == len(s):
        return ""
    # d < N[0] 
    if over:
        return O[0] + func(s, i+1, over=True)
    for d in O:
        if d < s[i]:
            continue
        if s[i] == d:
            return d + func(s, i+1, over=False)
        return d + func(s, i+1, over=True)

print(func(str(N), 0, over=False))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, K = map(int, input().split())
    D = set(list(map(int, input().split())))
    F = set(list(range(10))) - D
    result = ''
    for n in str(N):
        if int(n) in F:
            result += n
        else:
            result += str(min([f for f in F if f > int(n)]))
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)

for i in num:
    if i >= int(str(n)[0]):
        ans = i
        break


def dfs(pos, x):
    if pos == len(str(n)):
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


print(dfs(1, ans))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d_i = set(map(int, input().split()))
full = set(range(10))
useableList = full - d_i
useable_Top = full - d_i - set([0])
answer = []
isTop = True
for x in str(n):
    if int(x) in useableList: answer.append(x)
    elif isTop: answer.append(min(useable_Top - set(range(int(x) + 1))))
    else: answer.append(min(useableList))
    if isTop: isTop = False;
ans = ''
for x in range(len(answer)):
    ans += str(answer[x])
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d={int(x) for x in input().split()}
e={0,1,2,3,4,5,6,7,8,9}
f=list(d^e)
ans=[]
for i in f:
    for j in f:
        for k in f:
            for l in f:
                ans.append(1000*i+100*j+10*k+l)
ans=[m for m in ans if m>= n]
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
m,k=map(int,input().split())
d={int(x) for x in input().split()}
e={np.arange(10)}
f=list(d&e)
ans=[]
for i in f:
    for j in f:
        for k in f:
            for l in f:
                ans.append(1000*i+100*j+10*k+l)
print(min(ans))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    while s != 0:
      F += ND[s%(10-K)] * ju
      s //= 10 - K
      ju *= 10
    print(F, end = ' ')
  print(F)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    while s != 0:
      F += ND[s%(10-K)] * ju
      s //= 10 - K
      ju *= 10
  print(F)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
flg = True
while True:
  num = str(N)
  for i in range(len(num)):
    if num[i] in D:
      flg = False
      break
  if fig is True:
    print(int(num))
    break
  N += 1

Submission status: Runtime Error

Solution code:

if __name__ == "__main__":
    N,K = input().split()
    D = input().split()
    num = set([str(i) for i in range(10)])
    
    diff = num^set(D)
    print(diff)
    ans = N
    while True:
        strN = set(list(ans))
        if strN - diff:
            ans += 1
        else:
            break
    print(ans)

Submission status: Runtime Error

Solution code:

if __name__ == "__main__":
    N, K = input().split(" ")
    D = input().split()
    num = set([str(i) for i in range(10)])
    diff = num ^ set(D)

    temp = N
    while True:
        setN = set(list(N))
        if setN - diff:
            temp += 1
        else:
            break
    print(temp)