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: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [int(i) for i in input().split()]
N = []
while(n > 0):
    N.append(n % 10)
    n //= 10
N.reverse()
m = N.__len__()
d_c = [i for i in range(10)]
for i in d:
    d_c.remove(i)
for i in range(1,m):
    while(N[-i] in d):
        if N[-i] == 9:
            N[-i] = d_c[0]
            N[-i-1] += 1
        else:
            N[-i] += 1
while(N[0] in d):
    if N[0] == 9:
        N[0] = d_c[0]
        N.insert(0,1)
    else:
        N[0] += 1
new_n = 0
for i in range(N.__len__()):
    new_n += N[-i-1] * (10**i)
print(new_n)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 複数行の数値の入力を整数として取得
D = input().split()
D = list(map(lambda d: int(d), D))
len_list = [d_length == 1 for d_length in list(map(lambda d: len(str(d)), D))]
if all(len_list):
  if len(str(N))==1:
    if N <= min(D):
      PAYMENT = 10
    else:
      PAYMENT = N
  elif len(str(N))==2:
    if N/10 <= min(D):
      PAYMENT = int(str(N)[0])*10 + 10
    else:
      PAYMENT = N
  elif len(str(N))==3:
    if N/100 <= min(D):
      PAYMENT = int(str(N)[0])*100 + 100
    else:
      PAYMENT = N
  elif len(str(N))==4:
    if N/1000 <= min(D):
      PAYMENT = int(str(N)[0])*1000 + 1000
    else:
      PAYMENT = N
  print(PAYMENT)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession

"""
    1≦N<10000
    1≦K<10
    0≦D1<D2<…<DK≦9
    {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""

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

test_mode = False


def check_num(x, d, n):
    """
    金額xの中に中の文字があるか確認する関数。
    x : 現在の金額（N, x+n を想定）
    d : 嫌いな数字のリスト（D を想定）
    n : 元の金額（N を想定）
    文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
    含まれていたら元の金額 n を足して再試行する。
    """
    if test_mode:
        print('x =', x)
    if x >= 10000:
        return 0
    for num in d:
        if test_mode:
            print('num =', num)
        str_x = str(x)
        str_num = str(num)
        if str_num in str_x:
            return check_num(x+n, d, n)
    return x


def main():
    """
    金額を算出して出力
    """
    amount = check_num(N, D, N)
    print(amount)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d = list(input().split())
i = 0
while i<len(str(n)):
  while str(n)[-i-1] in d:
    n += 10**i
  i += 1
print(n)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(input().split())
frag = True
ans = 0
for i in range(1000000):
    N += 1
    if len(set(str(N)) & D) == 0:
        ans = N
        frag = False
        break
print(N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(input().split())
frag = True
ans = 0
for i in range(900000):
    N += 1
    if len(set(str(N)) & D) == 0:
        ans = N
        frag = False
        break
print(N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = set(input().split())
frag = True
ans = 0
for i in range(100000):
    N += 1
    if len(set(str(N)) & D) == 0:
        ans = N
        frag = False
        break
print(N)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
D=list(input())
for i in range(N,10001):
    flag=0
    for j in list(str(i)):
        if j in D:
            flag=1
    if flag==0:
        print(i)
        exit(0)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
D=list(input())
for i in range(N,10000):
    flag=0
    for j in list(str(i)):
        if j in D:
            flag=1
    if flag==0:
        print(i)
        exit(0)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
array = {int(x) for x in input().split()}
mihon = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}^array

for i in range(n, 10001):
    tmp = list(str(i))
    tmp = {int(x) for x in tmp}
    if tmp.issubset(mihon) and i >= n:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
array = {int(x) for x in input().split()}
mihon = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}^array

for i in range(n, 10001):
    tmp = list(str(i))
    tmp = {int(x) for x in tmp}
    if len(tmp.difference(mihon)) == 0 and i >= n:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    aUpper.sort()
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 : #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * iL
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,True) #逆行する
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False) #順行する
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
lis = list(map(str,input().split()))
cou = n
while 1:
  for i in range(d):
    if lis[i] in str(cou):
      break
    print(cou)
    exit()
  cou += 1

Submission status: Wrong Answer

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
sN = str(iN)

aRetList=[]
bFlagUp = False
for i in range(len(sN)-1,-1,-1):
    if bFlagUp :
        aUpper = [x for x in aUnList if x > int(sN[i])]
        if aUpper == [] :
            aRetList.append(str(aUnList[0]))
            if i == 0:
                if aUnList[0] == 0 :
                    aRetList.append(str(aUnList[1]))
                else:
                    aRetList.append(str(aUnList[0]))

        else:
            aRetList.append(str(min(aUpper)))
            bFlagUp = False

    else:
        aUpper = [x for x in aUnList if x >= int(sN[i])]
        if aUpper == [] :
            aRetList.append(str(aUnList[0]))
            bFlagUp = True
        else:
            aRetList.append(str(min(aUpper)))
aRetList.reverse()
print(''.join(aRetList))

Submission status: Wrong Answer

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
sN = str(iN)

aRetList=[]
iFlagUp = False
for i in range(len(sN)-1,-1,-1):
    if iFlagUp :
        aUpper = [x for x in aUnList if x > int(sN[i])]
        if aUpper == [] :
            aRetList.append(str(aUnList[0]))
            if i == 0:
                if aUnList[0] == 0 :
                    aRetList.append(str(aUnList[1]))
                else:
                    aRetList.append(str(aUnList[0]))

        else:
            aRetList.append(str(min(aUpper)))
    else:
        aUpper = [x for x in aUnList if x >= int(sN[i])]
        if aUpper == [] :
            aRetList.append(str(aUnList[0]))
            iFlagUp = 1
        else:
            aRetList.append(str(min(aUpper)))
aRetList.reverse()
print(''.join(aRetList))

Submission status: Wrong Answer

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

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]

for i in range(n, 10001):
    f = True
    for si in str(i):
        if int(si) in d:
            f = False
    if f:
        print(i)
        break

Submission status: Wrong Answer

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

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]

for i in range(n, 10000):
    f = True
    for si in str(i):
        if int(si) in d:
            f = False
    if f:
        print(i)
        break

Submission status: Wrong Answer

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

str_N = str(N)
inputs_set = set(inputs)
all_set = set({0,1,2,3,4,5,6,7,8,9})
rest_set = all_set - inputs_set

ans = ''

for i in range(len(str_N)):
    for rest in rest_set:
        if int(str_N[i]) <= rest:
            ans += str(rest)
            break

print(ans)

Submission status: Wrong Answer

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

str_N = str(N)
inputs_set = set(inputs)
all_set = set({0,1,2,3,4,5,6,7,8,9})
rest_set = all_set - inputs_set

ans = ''

for i in str_N:
    for rest in rest_set:
        if int(i) <= rest:
            ans += str(rest)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
rec = []
if n == 0:
    for i in range(10):
        if i not in d:
            print(i)
            break
else:
    while n > 0:
        mod = n % 10
        n = n // 10
        while mod in d:
            if mod == 9:
                n += 1
                mod = 0
            else:
                mod += 1
        rec.append(mod)
    rec = reversed(rec)
    print("".join(map(str, rec)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
rec = []
while n > 0:
    mod = n % 10
    n = n // 10
    while mod in d:
        if mod == 9:
            n += 1
            mod = 0
        else:
            mod += 1
    rec.append(mod)
rec = reversed(rec)
print("".join(map(str, rec)))

Submission status: Wrong Answer

Solution code:
(N,K)=map(int,input().split())
D=list(map(int,input().split()))
ans=""
while N>0:
    for i in range(10):
        if not N%10 in D:
            ans=str(N%10)+ans
            break
        else:
            N+=1
    N//=10
print(ans)

Submission status: Wrong Answer

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

def f(x):
    while True:
        if x in D:
            x += 1
        else:
            return x


X = [int(x) for x in str(N)]
ans = ''
for i in range(len(X)):
    if i == 0:
        ans += str(f(X[i]))
    else:
        y = f(X[i])
        if y == 10:
            X[i] += 1
            ans += '0'
        else:
            ans += str(y)
print(ans)

Submission status: Wrong Answer

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

for n in range(N, 10001):
    n = str(n)
    flag = True
    for ni in n:
        if ni in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

Submission status: Wrong Answer

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

for n in range(N, 10000):
    n = str(n)
    flag = True
    for ni in n:
        if ni in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(c)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
i=0
while i<len(str(n)):
   while int(str(n)[len(str(n))-i-1]) in d:
      print(int(str(n)[len(str(n))-i-1]) )
      n+=10**i
   i+=1
print(n)

Submission status: Wrong Answer

Solution code:
import itertools

n, k = map(int, input().split())
array = {x for x in input().split()}
num_array = {str(x) for x in range(10)}
like_num = array^num_array

res = float("inf")
for i in range(1, 10001):
    tmp = set(list(str(i)))
    if tmp.issubset(like_num):
        if n <= i < res:
            res = i
print(res)

Submission status: Wrong Answer

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

m = 0
while m < len(str(n)):
	if str(n)[~m] in d:
		n += 10**m
	else:
		m += 1
print(n)

Submission status: Wrong Answer

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

for i in range(len(str(n))):
	while str(n)[~i] in d:
		n += 10**i
print(n)

Submission status: Wrong Answer

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

for i in range(len(str(n))):
	if str(n)[~i] in d:
		n += 10**i
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
remain = [i for i in list(range(10)) if i not in d]
base = len(remain)

def calcBase(num):
    res = []
    while num>0:
        res.append(num%base)
        num //= base
    return res[::-1]

i = 1
while 1:
    s = ''
    for c in calcBase(i):
        s += str(remain[c])
    if int(s)>=n:
        print(s)
        break
    i += 1

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
n = list(str(n))
l = sorted(list(set(range(10)) - set(d)))
ans = []
for i in range(len(n)):
  n[i] = int(n[i])
  if n[i] in d:
    while n[i] in d:
      n[i] += 1
    for k in range(len(n[:i])):
      ans.append(str(n[k]))
    ans.append(str(n[i]))
    for j in range(len(n[i + 1:])):
      ans.append(str(min(l)))
    break
if ans:
  print("".join(ans))
else:
  print("".join(map(str, n)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
n = list(str(n))
ans = []
for i in n:
  i = int(i)
  while i in d:
    i += 1
  ans.append(str(i))
print("".join(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug  4 15:31:00 2018

@author: maezawa
"""

n, k = list(map(int, input().split()))
d = frozenset(list(map(str, input().split())))
ok = frozenset(list(map(str,range(10)))) - d

for i in range(n, 10000):
    if frozenset(str(i)) <= ok:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(input().split())
res = 0
for i in range(N,10000):
    if res != 0:
        break
    counter = 0
    for j in str(i):
        if j in D:
            break
        else:
            counter += 1
        if counter == len(str(i)):
            res = i
print(res)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(input().split())
res = 0
for i in range(N,10000):
    if res != 0:
        continue
    counter = 0
    for j in str(i):
        if j in D:
            continue
        else:
            counter += 1
        if counter == len(str(i)):
            res = i
print(res)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
kazu = [i for i in range(10)]
taisyou = []
for i in kazu:
    if not i in D:
        taisyou.append(i)
ans =''     
for i in list(str(N)):
    for j in taisyou:
        if j>=int(i):
            ans+=str(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = [int(x) for x in input().split()]
L = [str(i) for i in range(10) if i not in D]
ANS = ''
for i, n in enumerate(N):
  if n in L:
    ANS += n
  elif int(L[-1]) > int(n):
    ANS += [l for l in L if int(l) > int(n)][0]
    ANS += L[0] * (len(N) - len(ANS))
    break
  else:
    while ANS:
        c = ANS[-1]
        ANS = ANS[:-1]
        if int(L[-1]) > int(c):
          ANS += [l for l in L if int(l) > int(n)][0]
          break
    ANS += L[0] * (len(N) - len(ANS) + (0 if len(ANS) else 1))
    break
print(ANS)

Submission status: Wrong Answer

Solution code:
N, K = input().split()
D = [int(x) for x in input().split()]
L = [str(i) for i in range(10) if i not in D]
MAX = int(L[0] * 5)
ANS = ''
for i, n in enumerate(N):
  if n in L:
    ANS += n
  elif int(L[-1]) > int(n):
    ANS += [l for l in L if int(l) > int(n)][0]
    ANS += L[0] * (len(N) - i - 1)
    break
  else:
    while ANS:
        c = ANS[-1]
        ANS = ANS[:-1]
        if int(L[-1]) > int(c):
          ANS += [str(l) for l in L if l > int(n)][0]
          break
    ANS += L[0] * (len(N) - len(ANS) + (0 if len(ANS) else 1))
    break
print(ANS)

Submission status: Wrong Answer

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

import bisect
ans =''
i = 0
while i < len(str(N)):
    x = str(N)[::-1][i]
    if x in L:
        ans += x
        i = i + 1
        continue
    p = bisect.bisect_right(L, x)
    if p < len(L):
        ans += L[p]
    else:
        N += (10 + int(L[0]) - int(x)) * 10 ** i
        ans += L[0]
    i = i + 1
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = [Di for Di in input().split()]
for n in range(N, 10000):
    n = str(n)
    flag = True
    for i in range(len(str(n))):
        if n[i] in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

Submission status: Wrong Answer

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

arr = [0,1,2,3,4,5,6,7,8,9]
r = map(int,raw_input().split())

for i in r:
	arr.remove(i)


def count_digit(num):
	count = 0
	t = num 
	while t > 0 :
		count += 1
		t /= 10
	return count

dc = count_digit(n) 


ans = float("inf")

def dfs(s,i):
	global ans,n,dc
	if i == dc :
		ret = int(s)
		if ret >= n:
			ans = min(ans,ret)

	else :
		for j in arr :
			dfs(s + str(j),i + 1)

dfs('',0)
print ans

Submission status: Wrong Answer

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

arr = [0,1,2,3,4,5,6,7,8,9]
r = map(int,raw_input().split())

for i in r:
	arr.remove(i)

print arr

def count_digit(num):
	count = 0
	t = num 
	while t > 0 :
		count += 1
		t /= 10
	return count

dc = count_digit(n) 


ans = float("inf")

def dfs(s,i):
	global ans,n,dc
	if i == dc :
		ret = int(s)
		if ret >= n:
			ans = min(ans,ret)

	else :
		for j in arr :
			dfs(s + str(j),i + 1)

dfs('',0)
print ans

Submission status: Wrong Answer

Solution code:
import itertools

str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)

d = set([int(di) for di in input().split()])
opt = list({0,1,2,3,4,5,6,7,8,9} - d)

res = []
for opts in itertools.product(opt, repeat=len(str_n)+1):
    r = 0
    for i in range(0, len(str_n)+1):
        r += opts[i] * 10**i
    res.append(r)

for r in sorted(set(res)):
    if r >= n:
        print(r)
        break

Submission status: Wrong Answer

Solution code:
import itertools

str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)

d = set([int(di) for di in input().split()])
opt = list({0,1,2,3,4,5,6,7,8,9} - d)

res = []
for opts in itertools.product(opt, repeat=len(str_n)):
    r = 0
    for i in range(0, len(str_n)):
        r += opts[i] * 10**i
    res.append(r)

for r in sorted(set(res)):
    if r >= n:
        print(r)
        break

Submission status: Wrong Answer

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

N_str = str(N)

N_str_rv = list(N_str)[::-1]

i = 0
ans = []
while i<len(N_str_rv):
    flag = 1
    for num in range(int(N_str_rv[i]),10):
        if not num in D:
            ans.append(num)
            N += (num-int(N_str_rv[i]))*(10**i)
            N_str_rv = list(str(N))[::-1]
            #N_str_rv[i] = str(num)
            i+=1
            flag = 0
            break
    
    if flag:
        N += (10-int(N_str_rv[i]))*(10**i)
        N = N - N%(10**i)
        ans = []
        i = 0
        N_str_rv = list(str(N))[::-1]

answer = 0
for i,num in enumerate(ans):
    answer += num*(10**i)

print(answer)

Submission status: Wrong Answer

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

N_str = str(N)

N_str_rv = list(N_str)[::-1]

i = 0
ans = []
while i<len(N_str_rv):
    flag = 1
    for num in range(int(N_str_rv[i]),10):
        if not num in D:
            ans.append(num)
            N += (num-int(N_str_rv[i]))*(10**i)
            N_str_rv = list(str(N))[::-1]
            #N_str_rv[i] = str(num)
            i+=1
            flag = 0
            break
    
    if flag:
        N += (10-int(N_str_rv[i]))*(10**i)
        N = int(round(N,-i))
        ans = []
        i = 0
        N_str_rv = list(str(N))[::-1]

answer = 0
for i,num in enumerate(ans):
    answer += num*(10**i)

print(answer)

Submission status: Wrong Answer

Solution code:
import itertools, math

n, k = map(int, input().split())
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
ans = float("inf")

for cnt in range(10001):
    tmp = set(list(str(cnt)))
    if tmp <= nums and n <= cnt < ans:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools, math

n, k = map(int, input().split())
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
ans = float("inf")

for cnt in range(10001):
    tmp = set(list(str(cnt)))
    print(tmp, cnt)
    if tmp <= nums and n <= cnt < ans:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools, copy

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

res = map(str, {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} - array)
res2 = list(res)

array = itertools.product(res, repeat=len(str(n))+1)

ans = float("inf")
for i in array:
    tmp = int("".join(i))
    if n <= tmp < ans:
        ans = tmp

array = itertools.product(res2, repeat=len(str(n)))
for i in array:
    tmp = int("".join(i))
    if n <= tmp < ans:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

res = map(str, set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) - array)

array = itertools.product(res, repeat=len(str(n))+1)
ans = float("inf")
for i in array:
    tmp = int("".join(i))
    if n <= tmp < ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

res = map(str, set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) - array)

array = itertools.product(res, repeat=len(str(n)))
ans = float("inf")
for i in array:
    tmp = int("".join(i))
    if n <= tmp < ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
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 d:
    del a[a.index(i)]
for i in a:
    for j in a:
        for k in a:
            for l in a:
                for m in a:
                    p=int(i*10**4+j*10**3+k*10**2+l*10+m)
                    if p>=n:
                        break
                break           
            break
        break
    break
print(p)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
n = str(n)
ans = ''
for i, nn in enumerate(n):
    while(True):
        if int(nn) in d:
            nn = str(int(nn)+1)
        else:
            ans += nn
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
d = list(map(int, input().split()))
a = []
for i in range(10):
    if not i in d:
        a.append(str(i))
for i in range(n, 10000):
    tmp = str(i)
    ok = 0
    for j in tmp:
        if j in a:
            ok += 1
    if ok == len(tmp):
        break
print(int(tmp))

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
res = ''
while n > 0:
  b = n % 10
  n = n / 10
  plus = False
  while b in d:
    b += 1
    if b == 10:
      plus = True
      b = 0
  res = str(b) + res
  if plus:
    n += 1

print(res)

Submission status: Wrong Answer

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

word = list(map(int,list(str(N))))

z = 0
while z in Ds:
  z += 1

for i in range(len(word)):
  for j in range(len(Ds)):
    if word[-i-1] in Ds:
      word[-i-1] += 1
      if i > 0:
        word[-i:] = [z for i in range(i)]
      if word[-i-1]>=10:
        if i == len(word)-1:
          word.insert(0,0)
        word[-i-2] += 1
        word[-i-1:] += [z for i in range(i+1)]
s = list(map(str,word))

print(''.join(s))

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
unlike = list(map(int,input().split()))
like = [0]

for i in range(1, 10):
    if i not in unlike:
        like.append(i)

def func(arr):
    return list(map(int,list(str(arr))))

for i in range(n,80001):
    ans = func(i)
    if not(set(ans) - set(like)):
        print(''.join(map(str,ans)))
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
unlike = list(map(int,input().split()))
like = [0]
flg = False
for i in range(1, 10):
    if i not in unlike:
        like.append(i)

def func(arr):
    return list(map(int,list(str(arr))))

for i in range(n,10000):
    ans = func(i)
    if not(set(ans) - set(like)):
        print(''.join(map(str,ans)))
        break

Submission status: Wrong Answer

Solution code:
import itertools
n, k = map(int,input().split())
unlike = list(map(int,input().split()))
like = [0]
ans = []

def _join(arr):
    num = 0
    for i in range(len(str(n))):
        num += arr[i] * (10 ** (len(arr) - i - 1))
    return num

for i in range(1, 10):
    if i not in unlike:
        like.append(i)

def rev(arr):
    arr.reverse()
    return arr

arr = list(itertools.combinations_with_replacement(like,len(str(n))))

for i in arr:
    ans.append(_join(i))
    a = rev(list(i))
    ans.append(_join(a))
for i in  ans:
    if n <= i:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
d=list(input().split())
ans=10000
for i in range(n,10000):
    for j in d:
        if str(i).count(j):break
    else: 
        ans=i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
d=list(input().split())
ans=10000
for i in range(n,10000):
    for j in d:
        if str(i).count(j):break
    else: 
        ans=min(ans,i)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
d=list(map(int, input().split()))
ans=10000
for i in range(n,10001):
    for j in d:
        if str(i).count(str(j)):break
    else: 
        ans=min(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = [i for i in input().split()]
d = [i for i in input().split()]

# OK 숫자의 집합을 구하고,
# 각 자리수부터 들어가 NG 숫자를 OK숫자로 바꿔주면 되는 거 아냐?
n = list(n)
ng = set(d)
for i in range(len(n)):
#     print(ng)
    ok = set([str(i) for i in range(10)]) - ng
#     print(ok)
    if i == 0 and '0' in ok:
        ok.remove('0')
        ng.add('0')
    if n[i] in ng:
        n[i] = str(min(ok))
print(''.join(n))

Submission status: Wrong Answer

Solution code:
n, k = [i for i in input().split()]
d = [i for i in input().split()]

# OK 숫자의 집합을 구하고,
# 각 자리수부터 들어가 NG 숫자를 OK숫자로 바꿔주면 되는 거 아냐?
n = list(n)
ng = set(d)
for i in range(len(n)):
#     print(ng)
    ok = set([str(i) for i in range(10)]) - ng
#     print(ok)
    if i == 0 and '0' in ok:
        ok.remove('0')
    if n[i] in ng:
        n[i] = str(min(ok))
print(''.join(n))

Submission status: Wrong Answer

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

for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
    else:
      print(i)

Submission status: Wrong Answer

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

for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
    print(i)

Submission status: Wrong Answer

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

for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
      else:
        print(i)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d_list = list(map(int, input().split()))
num_list = [0,1,2,3,4,5,6,7,8,9]

for d in d_list:
  num_list.remove(d)

final_price = ''

def is_dislike_number(number, dislike_list):
  if number in dislike_list:
    return True
  else:
    return False

for i, num in enumerate(str(n)):
  num = int(num)
  if is_dislike_number(num, d_list):
    while num < 10:
      num += 1
      if num == 10:
        num = num_list[0] * 10 
      digit = len(str(n)) - i - 1
      if not is_dislike_number(num, d_list):
        final_price += str(num)
        for j in range(digit):
          final_price += str(num_list[0])
        print(final_price)
        exit()

  final_price += str(num)
print(final_price)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d_list = list(map(int, input().split()))
num_list = [0,1,2,3,4,5,6,7,8,9]

for d in d_list:
  num_list.remove(d)

final_price = ''

def is_dislike_number(number, dislike_list):
  if number in dislike_list:
    return True
  else:
    return False

for i, num in enumerate(str(n)):
  num = int(num)
  if is_dislike_number(num, d_list):
    while num < 10:
      num += 1
      digit = len(str(n)) - i - 1
      if not is_dislike_number(num, d_list):
        final_price += str(num)
        for j in range(digit):
          final_price += str(num_list[0])
        print(final_price)
        exit()

  final_price += str(num)
print(final_price)