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

Solution code:
n, k = map(int, input().split())
d = [int(i) for i in input().split()]
ablenum = [int(i) for i in range(10)]
lis_n = str(n)
lis_n = list(lis_n)

#print(lis_n)

# 使用可能な数一覧
for i in d:
    ablenum.remove(i)

#print(ablenum)

flag_bigdigit = -1

# max(ablenum)より大きい桁があるかどうか
for i in range(len(lis_n)):
    _i = len(lis_n) - i - 1
    if(int(lis_n[_i]) > max(ablenum)):
        flag_bigdigit = _i
        break

#  max(ablenum)より大きい桁があれば
if(flag_bigdigit != -1):
    flag_increaseDights = 1
    #  桁を増やす必要があるかどうか確認
    for i in range(flag_bigdigit-1, 0):
        # nの桁より大きい数字がablenumに存在していれば桁を増やす必要はない
        if(int(lis_n[i]) < max(ablenum)):
            flag_increaseDights = 0
            break
else:
    flag_increaseDights = 0

#print("bigdigit:{0} increace:{1}".format(flag_bigdigit, flag_increaseDights))

ans = ""
# 桁を増やす必要があるならば
if(flag_increaseDights == 1):
    for i in range(len(lis_n)+1):
        # 一桁目は0以外の最も小さな数
        if(i == 0):
            mnum = min(ablenum)
            if(mnum == 0):
                mnum = ablenum[1]
            ans += str(mnum)
        # 2桁目以降は最も小さい数
        else:
            mnum = min(ablenum)
            ans += str(mnum)
# 桁を増やす必要がなければ、各桁の数字以上の最も小さい数を使う
else:
    flag_over = 0
    for i in range(len(lis_n)):
        if(flag_over == 0):
            mnum = min(ablenum)
            # その桁以上の数になるまで大きくする
            j = 0
            while mnum < int(lis_n[i]):
                #print("mnum:{0} j:{1}".format(mnum, j))
                j += 1
                mnum = ablenum[j]
            if(mnum > int(lis_n[i])):
                flag_over = 1
            ans += str(mnum)
        else:
            mnum = min(ablenum)
            ans += str(mnum)

print(ans)

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().split())
D = map(int, sys.stdin.readline().split())

for i in xrange(N * 10):
    if i >= N:
        temp = i
        isCorrect = True
        while temp > 0:
            if (temp % 10) in D:
                isCorrect = False
                break
            else:
                temp /= 10
        if isCorrect:
            print i
            break

Submission status: Accepted

Solution code:
n,k=map(int,raw_input().split())
d=[i for i in raw_input().split()]
while True:
    f=True
    for i in d:
        if i in str(n):
            f=False
            break
    if f:
        break
    n+=1
print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
    f=True
    for i in d:
        if i in str(n):
            f=False
            break
    if f:
        break
    n+=1
print(n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
S = input().split()
		
flag = False

for i in range(N, 10*N):
	for k in range(len(str(i))):
		if str(i)[k] in S:
			flag = False
			break
		else:
			flag = True
			continue
		
	if flag:
		print(i)
		break

Submission status: Accepted

Solution code:
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)

if candi[-1] * len(N) >= N:
    print decide(0)
else:
    print (candi[0] if candi[0] != '0' else candi[1]) + candi[0] * len(N)

Submission status: Accepted

Solution code:
# B
N, L = [int(i) for i in input().split()]
D = sorted([i for i in input().split()])

for i in range(N, 100000):
    if all([s not in D for s in list(str(i))]):
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(100000):
    for x in str(N):
        if x in D:
            break
    else:
        print N
        break
    N += 1

Submission status: Accepted

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

while True:
        if set(map(int,list(str(N)))) & D_set:
                N += 1
        else:
                break

print(N)

Submission status: Accepted

Solution code:
N,K = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))
n = [int(c) for c in str(N)]
len_n = len(n)
digits = []
for i in range(10):
    if not(i in A):
        digits.append(i)


def need_big_keta():
    if n[0] <  digits[-1]:
        return False
    i=0
    while i < len_n and n[i] == digits[-1] :
        i+=1
    if i==len_n:
        return False
    if n[i] < digits[-1]:
        return False
    return True

if not need_big_keta():
    for i in range(N,int("9"*len_n)+1):
        j = i
        flag = True
        while j:
            if not j%10 in digits:
                flag = False
                break
            j/=10
        if flag:
            print i
            break
elif 0 in digits:
    print str(digits[1])+"0"*len_n
else:
    print str(digits[0])*(len_n+1)

Submission status: Accepted

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

d = input().split()

def check(c):
    for i in d:
        if str(c).count(i): return False
    return True

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

Submission status: Accepted

Solution code:
class IrohasObsession:
	def getMinimumValue(self,n,k,d):
		nums=list(set(d)^set([0,1,2,3,4,5,6,7,8,9]))
		for i in range(100000):
			digits=[int(str(n)[i]) for i in range(len(str(n)))]
			flag=1
			for j in range(len(digits)):
				if not digits[j] in nums: flag=0
			if flag: print n; return
			n+=1
		print -1

if __name__ == "__main__":
	n,k=[int(i) for i in raw_input().split()]
	d=[int(i) for i in raw_input().split()]
	i=IrohasObsession()
	i.getMinimumValue(n,k,d)

Submission status: Accepted

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

dp = [True]*10
for e in D:
	dp[e] = False

def calc(s):
	res = True
	for c in s:
		if not dp[int(c)]:
			res = False
			break
	return res

while True:
	if calc(str(N)):
		break
	else:
		N += 1

print(N)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
Ds=list(input().split())
Di=list(map(int,Ds))
nex=[1]*10
for i in reversed(Di):
    nex[i-1]=nex[i]+1

def check(n):
    ns = str(N)
    for nss in ns:
        if nss in Ds:
            return False
    return True

def next(i):
    global N
    ns='{0:0>5}'.format(N)
    t=nex[int(ns[i])]
    pp=int(ns[i])+t
    if pp >=10:
        t=t-10
        N+=t*(10**(4-i))
        next(i-1)
    else:
        N+=t*(10**(4-i))

while not check(N):
    next(4)
print(N)

Submission status: Accepted

Solution code:
def solve():
    n, k = map(int, input().split())
    d = set(input().split())
    while True:
        s = str(n)
        for x in d:
            if x in s:
                break
        else:
            print(s)
            break
        n += 1


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def check(num,D):
    numStr = str(num)
    for i in range(len(numStr)):
        if int(numStr[i]) in D:
            return False
    return True

n = int(N)
for i in range(n,100000):
    if check(i,D):
        print( i )
        break

Submission status: Accepted

Solution code:
import re


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        n, k = IO_for_Contest.read_n_int(2)
        return n, IO_for_Contest.read_n_int(k)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
            int,
            re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    n, d = IO_for_Contest.read_from_input()
    print(min_value_can_pay(n, d))


def min_value_can_pay(n, d):
    ints_can_be_used = think_ints_can_be_used(d)
    queue = []
    for i in ints_can_be_used:
        queue.append(i)
    while len(queue) > 0:
        j = queue.pop(0)
        if j >= n:
            return j
        if j == 0:
            continue
        for i in ints_can_be_used:
            queue.append(j * 10 + i)


def think_ints_can_be_used(d):
    ints = list(range(10))
    for i in d:
        ints.remove(i)
    return ints

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    solve()

Submission status: Accepted

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

for i in range(N, N*10):
	if all(d not in str(i) for d in D):
		print(i)
		break

Submission status: Accepted

Solution code:

def check_number(ans):
    ans = map(int,list(str(ans)))
    for i in range(len(ans)):
        for j in range(K):
            if ans[i]==number[j]:
                return 0
    return 1

if __name__ == '__main__':
    N,K = map(int,raw_input().split())
    number = map(int,raw_input().split())

    ans = N
    count = 0
    while(count == 0):
        count = check_number(ans)
        if (count == 0):
            ans += 1

    print ans

Submission status: Accepted

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

for x in range(N, N * 10):
    if all(d not in str(x) for d in D):
        print(x)
        break

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = map(str, raw_input().split())
while True:
    if any(l in D for l in str(N)):
        N += 1
    else:
        print N
        break

Submission status: Accepted

Solution code:
#coding: utf-8
#ABC042C

n,k=map(int,raw_input().split())
d=raw_input().split()

while True:
 if all(x not in str(n) for x in d):
  res=n
  break
 n+=1
 
print res

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
oknums = set(range(10)) - set(map(int, input().split()))

def can(ans):
	digits = map(int, list(str(ans)))
	for d in digits:
		if not d in oknums:
			return False
	return True

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

Submission status: Accepted

Solution code:
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = sorted(set(range(10)) - set(Bad))
NotZero = sorted(set(OK) - set([0]))

if any(d > str(OK[-1]) for d in S):
    print(str(NotZero[0]) + str(OK[0]) * len(S))
    sys.exit()

count = [0] * 10
for c in str(S):
    count[ord(c) - ord('0')] += 1
greater = 0
ans = []


def can(i, d):
    c = str(d)
    if i == 0 and d == 0 and len(S) > 1:
        return 0
    if not greater and c < S[i]:
        return 0
    if c > S[i]:
        return 1
    for b in range(10):
        if count[b] > 0 and b > OK[-1]:
            return 0
    return 1

for i in range(len(S)):
    count[ord(S[i]) - ord('0')] -= 1
    for d in OK:
        if can(i, d):
            if str(d) > S[i]:
                greater = 1
            ans.append(d)
            break

print("".join(str(a) for a in ans))

Submission status: Accepted

Solution code:
S, K = map(int, input().split())
Bad = list(input().split())

while 1:
    if all(d not in str(S) for d in Bad):
        print(S)
        break
    S += 1

Submission status: Accepted

Solution code:
import itertools
ini = int(input().split(" ")[0])
try:
    negaset = [int(x) for x in input().split(" ")]
except :
    print (ini)
    exit()
okset = sorted([str(i) for i in range (10) if i not in negaset]) 
#print(ini,okset)

for p in [int("".join(j)) for j in itertools.chain.from_iterable (itertools.product(okset,repeat = i)  for i in range (len(str(ini)),len(str(ini))+2) )]:
    if p >= ini:
        print(p)
        break

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())
n = N
while True:
    s = str(n)
    if all(str(d) not in s for d in D):
        print n
        break
    n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
drr=map(int,input().split())
digits = set(map(str,set([0,1,2,3,4,5,6,7,8,9])-set(drr)))
#print(digits)
for i in range(n,100000):
#    print(i,set(str(i)))
    if set(str(i)).issubset(digits):
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dislike = input().split()
i = 0
while True:
    money = str(n + i)
    if len(set(money).intersection(dislike)) == 0:
        print(money)
        break
    i += 1

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = raw_input().split()
while any(s in D for s in str(N)):
    N += 1
print N

Submission status: Accepted

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

def main():
    N, K = map(int, input().split())
    D = input().split()
    i = N
    while True:
        if len(set(str(i)).intersection(D)) == 0:
            print(i)
            break
        i += 1

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Ds = input().split()
for v in range(N, N*10 + 1):
    strv = str(v)
    for d in Ds:
        if d in strv:
            break
    else:
        print(v)
        break

Submission status: Accepted

Solution code:
def no_dislike_number(num, D):
    for digit in num:
        if digit in D:
            return False
    return True
    # for dislike in D:
    #     if dislike in num:
    #         return False
    # return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

Submission status: Accepted

Solution code:
#coding=UTF-8

mojir=input()
hyo=mojir.split(' ')

N=int(hyo[0])
K=int(hyo[1])

mojir=input()
hyo=mojir.split(' ')
D=[int(mono) for mono in hyo]

kouho=N

def usecheck(gaku):
    gakustr=str(gaku)
    keta=len(gakustr)
    dame=None
    for idx in range(0,keta,1):
        if gakustr[idx] in hyo:
            dame=idx
            break

    if dame == None:
        return None
    else:
        return (keta-dame)

#積極的に枝刈りを
while True:
#    print(kouho)
    dameketa=usecheck(kouho)
    if dameketa == None:
        break

    kouho=(kouho//(10**(dameketa-1)) +1)*(10**(dameketa-1))

print(kouho)

Submission status: Accepted

Solution code:
import itertools
N, K = map(int, raw_input().split())
d = map(int, raw_input().split())
d = set(d)
ok = set(range(10)) - d
ok = sorted(list(ok))
ok = [str(i) for i in ok]
i = 1
while True:
    for ele in itertools.product(ok, repeat=i):
        if int("".join(list(ele))) >= N:
            print "".join(list(ele))
            exit()
    i += 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python2
#encoding: UTF-8

# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
import math
line=raw_input().rstrip().split(' ')
N=int(line[0])
K=int(line[1])
Disto=raw_input().rstrip().split(' ')
Tru=True
while(Tru):
	Tru=False
	for args in Disto:
		for i in range (len(str(N))):
			if str(N)[i]==args:
				N+=1
				Tru=True
print N

Submission status: Accepted

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

D = map(int, raw_input().split())

for i in range(N, 1000000):

  flag = 0

  for j in D:
    if str(j) in str(i):
      flag = 1
      break

  if flag == 0:
    print i
    exit()

Submission status: Accepted

Solution code:
import itertools,math,bisect,pprint,sys

n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()

Submission status: Accepted

Solution code:
cond = [int(n) for n in input().split(" ")]
exclude = {n for n in range(10)}
answer = ""
mo = {str(n) for n in input().split(" ")}
exclude = exclude - mo
for n in range(cond[0],100000):
    for m in [n for n in str(n)]:
        if m in mo:
            break
    else:
        print(n)
        break

Submission status: Accepted

Solution code:
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())

l = map(int, raw_input().split())
flag = False

while flag == False:
	flag = True
	t = n
	while t > 0:
		m = t % 10
		if m in l:
			flag = False
			break
		t = t / 10
	n += 1

print n - 1

Submission status: Accepted

Solution code:
def read():
    return map(int, input().split())

n, k = read()
d = set(read())

nset = set(map(int, str(n)))
while nset.intersection(d):
    n += 1
    nset = set(map(int, str(n)))
print(n)

Submission status: Accepted

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


for i in range(n,10**7):
    ans=set(str(i))

    for j in ans:
        if j in d:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
K = int(l[1])

a = raw_input().split()

like={}

for i in range(10):
    if str(i) in a:
        like.setdefault(i,False)
    else:
        like.setdefault(i,True)
    

while(True):
    ok = True
    num_str = str(N)
    for s in num_str:
        if like[int(s)] is False:
            if(ok): N += 1
            ok = False
            continue

    if(ok):
        print N
        sys.exit()

Submission status: Accepted

Solution code:
N, _ = [int(x) for x in input().split()]
D = set(range(10)) - set([int(x) for x in input().split()])
n = [int(x) for x in list(str(N))]

i = 0
while i < len(n):
    if n[i] not in D:
        cand = {x for x in D if x > n[i]}
        if len(cand) > 0:
            n[i] = min(cand)
            for j in range(i + 1, len(n)):
                n[j] = 0
            i += 1
        elif i > 0:
                n[i - 1] += 1
                n[i] = 0
                i -= 1
        else:
            n = [1] + [0] * len(n)
    else:
        i += 1

print(''.join([str(x) for x in n]))

Submission status: Accepted

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

ans = n
f = 0
while True:
    ansstr = list(str(ans))
    l = len(ansstr)
    cnt = 0
    for i in range(l):
        if ansstr[i] in d:
            break
        else:
            cnt += 1
            if cnt == l:
                f = 1
                break

    if f:
        break

    ans += 1

print(ans)

Submission status: Accepted

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

while True:
    current_digits = set(str(n))
    if current_digits & d:
        n += 1
    else:
        break

print(n)

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = "".join(raw_input().strip().split())
i = N
while True:
    flag = True
    for c in str(i):
        if c in D:
            flag = False
    if flag:
        print i
        break
    i += 1

Submission status: Accepted

Solution code:
#coding :utf-8                                                                                                                                              
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())

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

print N

Submission status: Accepted

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

while True:
    S = str(N)
    t = 0
    for x in S:
        if x not in D:
            t += 1
    if t == len(S):
        print(S)
        break
    else:
        N += 1

Submission status: Runtime Error

Solution code:
import math

total = list(map(lambda x: int(x), input().split()))
possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split()))))
yen = total[0]
digits = math.log10(yen) + 1

final = []
while digits:
    if yen % (10**digits) in possible:
        final.append(int(yen % (10**digits)))
    else:
        for i in possible:
            if i > yen % digits:
                final.append(int(i))
                break

    digits -= 1

print(int(''.join(map(str, final))))

Submission status: Runtime Error

Solution code:
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin+=str(k)
            i+=1
        else:fin+=str(find(1))
        fin+=str(find(0))*(len(n)-i)
        break

p

Submission status: Runtime Error

Solution code:
n, k= map(int,input().split())
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]
for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]
def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x
fin=""
remain=0

if n==0:
    fin=str(find(0))

while n>0 or remain>0:
    last=n%10
    k=find(last+remain)
    remain=0
    if k!=10:
        fin=str(k)+fin
    else:
        remain+=1
        fin=str(find(0))+fin
    n//=10
print(fin)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind-1,-1,-1):
        n = int(N[i])
        if n==E[-1]:continue
        else:
            for e in E:
                if e>n:
                    x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                    flag = 1
                    break
            if flag==1:break
    if flag==0:
        for e in E:
            if e>int(N[0]):
                a = e
                flag = 1
                break
        x = str(a)+str(E[0])*(len(N)-1)
        if flag==0:
            if E[0]>0:
                a = E[0]
            else:
                a = E[1]
            x = str(a)+str(E[0])*len(N)
    print(x)

Submission status: Runtime Error

Solution code:
def answer(n: int, k: int, d: []) -> int:
    numbers = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(d))
    payment = ''
    for i in str(n):
        for num in numbers:
            if int(i) <= num:
                payment += str(num)
                break
    return int(payment)


def main():
    n, k = map(int, input().split())
    d = map(int, input().split())
    print(answer(n, k, d))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ok = [i for i in range(10) if i not in D]
    N = str(N)
    l = len(N)
    if {i for i in range(int(N[0]), 10)} <= D:
        if ok[0] == 0:
            ans = ok[1] * 10 ** l
            print(ans)
    else:
        ans = 0
        for c in N:
            ans *= 10
            idx = bisect_left(ok, int(c))
            ans += ok[idx]
        print(ans)




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N, L = [int(x) for x in input().split()]
S = []
for s in range(N):
    S.append(input())
print("".join(sorted(S)))

# %% [markdown]
#
# C
#

# %%
N, K = [int(x) for x in input().split()]
dislikes = [False] * 10
dislike_nums = [int(x) for x in input().split()]
for n in dislike_nums:
    dislikes[n] = True

# Add '0' in the beginning of N for carrying up
N = "0" + str(N)

# Create a list of numbers consists N
n_list = []
for n in N:
    n_list.append(int(n))
# Create a list of carrying up numbers
c_list = [0] * len(n_list)

# Create the smallest payment
payment = ""
for i in range(len(n_list) - 1, -1, -1):
    n = n_list[i] + c_list[i]
    if i == 0 and n == 0:
        break
    # Find an equal or larger number than n and not in dislikes
    x = -1
    for m in range(n, 10):
        if not dislikes[m]:
            x = m
            break
    if x >= 0:
        # found a number
        payment = str(m) + payment
        continue

    # Carry a number to the previous (x10) digit
    if i > 0:
        c_list[i - 1] += 1

    # Find a smaller number than n and not in dislikes
    for m in range(0, n):
        if not dislikes[m]:
            payment = str(m) + payment
            break
print(int(payment))

Submission status: Runtime Error

Solution code:
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
    else:
        return str(usable[0])


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()

    Nstr = list(str(N))
    ans = ''
    flag = True
    for n in Nstr:
        n = int(n)
        if flag:
            if n in D:
                ans += minN(n, d)
                flag = False
            else:
                ans += str(n)
        else:
            ans += str(min(d))
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from itertools import chain
from bisect import bisect_left

# from collections import Counter
# import numpy as np


def solve(N: int, K: int, D: "List[int]"):
    nr = list(map(int, reversed(str(N))))
    over = False
    answer = []
    useable = sorted(set(range(10)) - set(D))
    if nr[0] not in useable:
        nr = [0] + nr
    for n in nr:
        if over:
            answer.append(useable[0])
        else:
            a = useable[bisect_left(useable, n)]
            answer.append(a)
            if a > n:
                over = True
    return "".join(map(str, reversed(answer)))


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, D = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    answer = solve(N, K, D)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

n,k = map(int, raw_input().split())
letters = [u for u in range(10) if u not in set(map(int, raw_input().split()))]
def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u

print dfs(0,n,letters)

Submission status: Runtime Error

Solution code:
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Submission status: Runtime Error

Solution code:
total, k = map(int, input().split())

d = input().split()

def find_lowest_denomination(total, d):
    for i in range(total, 10001):
        if not set(str(i)) & set(d):
            print(i)
            return
    raise ValueError('Should never reach this code block')



find_lowest_denomination(total, d)

Submission status: Runtime Error

Solution code:
from itertools import combinations_with_replacement, product
n, k = map(int, input().split())
d = [int(x) for x in input().split()]
dd = set(list(range(10))) - set(d)

x = str(n)
lst = []
dd = list(dd)
dd.sort()
sel = []
for i in dd:
    if int(x[0]) <= i and len(sel) < 3: sel.append(i*10**(len(x)-1))
if len(sel) < 2:
    if dd[0] != 0:
        sel.append((dd[0]*10 + dd[1])* 10 ** (len(x)-1))
    else:
        sel.append((dd[1]*10 + dd[0])* 10 ** (len(x)-1))
for j in sel:
    for l in combinations_with_replacement(dd, len(x)-1):
        cnt = j
        for i in range(len(x)-1):
            cnt += 10 ** (len(x)-i-2) * l[i]
        if cnt >= n: lst.append(cnt)
print(min(lst))

Submission status: Runtime Error

Solution code:
import itertools

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

D = list(map(int, input().split()))
dic = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    dic.remove(i)

dict = map(str, dic)
n = len(str(N)) #何桁か

ans = []
for i in range(2):
    for v in itertools.permutations(dict, n+i):
        if int(''.join(v)) >= N:
            ans.append(int(''.join(v)))
print(min(ans))

Submission status: Runtime Error

Solution code:
kingaku, n = input().split()
no_num = input().split()
result = []
ok_num = []
kuriage_num = [-1, 0]

def kuriage(l):
    for i in ok_num:
        if result[l] < i:
            kuriage_num = [l, i]
            return
    if l <= 0:
        return
    return kuriage(l-1)

#使える数字のリストを作成
for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        ok_num.remove('0')
        print(ok_num[0].ljust(len(kingaku)+1, '0'))
        exit()

print(''.join(result))