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, _ = list(map(int, input().split()))
d = set(input().replace(" ", ""))

for i in range(1,1000001):
  n = str(N*i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
N, _ = list(map(int, input().split()))
d = set(input().replace(" ", ""))

for i in range(1,100001):
  n = str(N*i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)

Submission status: Wrong Answer

Solution code:
in_len = input().split(" ")
in_d = input().split(" ")

in_n = in_len[0]
in_k = int(in_len[1])

cmp_len = ['0','1','2','3','4','5','6','7','8','9']
use_num = sorted(list(set(cmp_len) - set(in_d)), reverse=False)
use_cnt = 10 - in_k
out = []

for i in range(len(in_n)):
  for j in range(use_cnt):
    if(i == 0 and in_n[i] >= use_num[j]):
      out.append(min(list(set(use_num) - set(['0'])))+'0')
      break
    else:
      if(in_n[i] >= use_num[j]):
        out.append(use_num[j])
        break

print("".join(out))

Submission status: Wrong Answer

Solution code:
in_len = input().split(" ")
in_d = input().split(" ")

in_n = in_len[0]
in_k = int(in_len[1])

cmp_len = ['0','1','2','3','4','5','6','7','8','9']
use_num = sorted(list(set(cmp_len) - set(in_d)), reverse=False)
use_cnt = 10 - in_k
out = []

for i in range(len(in_n)):
  for j in range(use_cnt):
    if(in_n[i] <= use_num[j]):
      out.append(use_num[j])
      break
    
    if(j == use_cnt-1):
      out.append(min(list(set(use_num) - set(['0'])))+'0')
      break
print("".join(out))

Submission status: Wrong Answer

Solution code:
in_len = input().split(" ")
in_d = input().split(" ")

in_n = in_len[0]
in_k = int(in_len[1])

cmp_len = ['0','1','2','3','4','5','6','7','8','9']
use_num = sorted(list(set(cmp_len) - set(in_d)), reverse=False)
use_cnt = 10 - in_k
out = []

for i in range(len(in_n)):
  for j in range(use_cnt):
    if(in_n[i] <= use_num[j]):
      out.append(use_num[j])
      break

print("".join(out))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, K = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    Dset = set(D)

    for i in range(N, 10000):
        for j in str(i):
            if int(j) in Dset:
                break
        else:
            print(i)
            return


    
    
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ok = set(("0","1","2","3","4","5","6","7","8","9"))-set(D)

def solve(str_num):
    ans = 100000
    if str_num == "":
        for c in ok:
            if c == "0":
                continue
            ans = min(ans,solve(str_num+c))

    else:
        for c in ok:
            new_num = str_num+c
            if N <= int(new_num):
                ans = min(ans,int(new_num))
            else:
                ans = min(ans,solve(new_num))
    return ans

if N<10:
    ans = 10
    for c in ok:
        if N <= int(c):
            ans = min(ans,int(c))
    print(ans)
else:
    print(solve(""))

Submission status: Wrong Answer

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

ok = set(("0","1","2","3","4","5","6","7","8","9"))-set(D)

def solve(str_num):
    ans = 100000
    if str_num == "":
        for c in ok:
            if c == "0":
                continue
            ans = min(ans,solve(str_num+c))

    else:
        for c in ok:
            new_num = str_num+c
            if N <= int(new_num):
                ans = min(ans,int(new_num))
            else:
                ans = min(ans,solve(new_num))
    return ans

print(solve(""))

Submission status: Wrong Answer

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

for i in range(n,n*10+1):
    if i>=n and len(set(str(i))&D)==0:
        print(i)
        break

Submission status: Wrong Answer

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

ans = ''
kuriagari = 0
for c in reversed(str(N)):
    c = str(int(c) + kuriagari)
    if int(c) > 9:
        kuriagari = 1
        c = '0'
    else:
        kuriagari = 0
    while True:
        if c in D:
            if c == '9':
                kuriagari += 1
                c = '0'
            else:
                c = str(int(c) + 1)
        else:
            ans += c
            break
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N, K = [int(x) for x in input().split()]
D = [str(x) for x in input().rstrip().split()]
D = set(D)
for i in range(N, N + 10 ** 4):
    i_list = list(str(i))
    flag = 1
    for j in i_list:
        if j in D:
            flag = 0
            break
    if flag:
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N, K = [int(x) for x in input().split()]
D = [str(x) for x in input().rstrip()]
D = set(D)
for i in range(N, N + 10 ** 4):
    i_list = list(str(i))
    for j in i_list:
        if j in D:
            break
    print(i)
    sys.exit()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc042/submissions/9653489

import itertools
N, K = input().split()
P = input().split()

#使える数字
a= sorted(set([str(i) for i in range(10)])-set(P))
#同じ桁
#b1 = itertools.product(a, repeat=len(N))
#繰り上がって一つ大きい桁
b2 = itertools.product(a, repeat=len(N)+1)
ans=str()
cnt=0
"""
for i in b1:
  #print(type(i))
  ans = "".join(i)
  if N <= ans:
    print(ans)
    cnt=1
    break
if cnt==0:
"""
for i in b2:
  ans = "".join(i)
  #print(ans)
  if "0"+N <= ans:
    if ans[0] == "0":
      print(ans[1:])
    else:
      print(ans)
    break

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc042/submissions/9653489

import itertools
N, K = input().split()
P = input().split()

#使える数字
a= sorted(set([str(i) for i in range(10)])-set(P))
#同じ桁
b1 = itertools.product(a, repeat=len(N))
#繰り上がって一つ大きい桁
b2 = itertools.product(a, repeat=len(N)+1)
ans=str()
cnt=0
for i in b1:
  #print(type(i))
  ans = "".join(i)
  if N <= ans:
    print(ans)
    cnt=1
    break
if cnt==0:
  for i in b2:
    ans = "".join(i)
    if N <= ans:
      print(ans)
      break

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc042/submissions/9653489

import itertools
N, K = input().split()
P = input().split()

#使える数字
a= sorted(set([str(i) for i in range(10)])-set(P))
#同じ桁
b1 = itertools.product(a, repeat=len(N))
#繰り上がって一つ大きい桁
b2 = itertools.product(a, repeat=len(N)+1)
ans=str()
cnt=0
for i in b1:
  #print(type(i))
  ans = "".join(i)
  if N <= ans:
    print(ans)
    cnt=1
    break
if cnt==1:
  for i in b2:
    ans = "".join(i)
    if N <= ans:
      print(ans)
      break

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
A=[i for i in range(10) if i not in D]
num=list(map(int,str(n).zfill(10)))
ans=""
for i in range(10):
    for j in A:
        if num[i]<=j:
            ans +=str(j)
            break
for i in range(len(list(str(n))),10):
    rate=int("".join(ans[-i:]))
    if rate>=n:
        print(rate)
        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
A=[i for i in range(10) if i not in D]
num=list(map(int,str(n).zfill(5)))
ans=""
for i in range(5):
    for j in A:
        if num[i]<=j:
            ans +=str(j)
            break
for i in range(len(list(str(n))),6):
    rate=int("".join(ans[-i:]))
    if rate>=n:
        print(rate)
        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
A=[i for i in range(10) if i not in D]
num=list(map(int,str(n).zfill(5)))
ans=""
for i in range(5):
    for j in A:
        if num[i]<=j:
            ans +=str(j)
            break
print(int("".join(ans)))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
A=[i for i in range(10) if i not in D]
num=list(map(int,str(n)))
ans=""
for i in range(len(num)):
    for j in A:
        if num[i]<=j:
            ans +=str(j)
            break
print("".join(ans))

Submission status: Wrong Answer

Solution code:
N, L = map(str, input().split())
K = N
P = list(map(str, input().split()))
U = sorted(list(set([str(i) for i in range(10)])-set(P)))

#K = str()
for i in range(len(N)):
    if N <= K:
        if N[i] in P:
            #print(N[i])
            for j in U:
                if j >=N[i]:
                    N=N.replace(N[i],j)
                    #print(N)
                    break
    else:
        if N[i] in P:
            N=N.replace(N[i],U[0])
print(N)

Submission status: Wrong Answer

Solution code:
import itertools

N, L = map(str, input().split())
P = list(map(str, input().split()))

U = itertools.combinations_with_replacement(list(set([str(i) for i in range(10)])-set(P)),10-len(P))
K = str()
for i in U:
    K = ''.join(i)
    if K>=N:
        print(K)
        break

Submission status: Wrong Answer

Solution code:
N, L = map(str, input().split())
K = int(N)
P = list(map(str, input().split()))
U = sorted(list(set([str(i) for i in range(10)])-set(P)))
for i in range(len(N)):
    if int(N) <= K:
        if N[i] in P:
            for j in U:
                if j >=N[i]:
                    N=N.replace(N[i],j)
                    break
    else:
        if N[i] in P:
            N=N.replace(N[i],U[0])
print(N)

Submission status: Wrong Answer

Solution code:
N, L = map(str, input().split())
P = list(map(str, input().split()))
U = sorted(list(set([str(i) for i in range(10)])-set(P)))
#print(U)
for i in range(len(N)):
    #print(N[i])
    if N[i] in P:
        #print(N[i])
        for j in U:
            #print(j)
            if j >=N[i]:
                N=N.replace(N[i],j)
                #print(N)
                break
print(N)

Submission status: Wrong Answer

Solution code:
N, L = map(str, input().split())
P = list(map(str, input().split()))
U = sorted(list(set([str(i) for i in range(10)])-set(P)))
#print(U)
for i in range(len(N)):
    #print(N[i])
    if N[i] in P:
        print(N[i])
        for j in U:
            print(j)
            if j >=N[i]:
                N=N.replace(N[i],j)
                #print(N)
                break
print(N)

Submission status: Wrong Answer

Solution code:
import os

if __name__ == "__main__":
    temp = input().split(" ")
    N = temp[0]
    L = int(temp[1])
    D = list(map(int, input().split(" ")))
    
    like = []
    for i in range(0, 10):
        if D.count(i) == 0:
            like.append(i)
   
    ans = []
    for n in N:
        for l in like:
            if int(l) >= int(n):
                ans.append(l)
                break
    print("".join(map(str, ans)))

Submission status: Wrong Answer

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

for i in range(N, 10000):
    str_i = str(i)
    if any([d in str_i for d in dislikes]):
        continue
    print(i)
    break

Submission status: Wrong Answer

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

for i in range(N, 10000):
    str_i = str(i)
    if all([d not in str_i for d in dislikes]):
        print(i)
        break

Submission status: Wrong Answer

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

ans = []
is_zero = True
for i in range(N, 10000):
    str_i = str(i)
    if all([d not in str_i for d in dislikes]):
        print(i)
        is_zero = False
        break
if is_zero:
    print(0)

Submission status: Wrong Answer

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

ans = []
is_zero = False
for i in range(N, 10000):
    str_i = str(i)
    if all([d not in str_i for d in dislikes]):
        print(i)
        is_zero = True
        break
if is_zero:
    print(0)

Submission status: Wrong Answer

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

ans = []
for i in range(N, 10000):
    str_i = str(i)
    if all([d not in str_i for d in dislikes]):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import itertools

list_of_num = list(range(10))
inputs = input().split(' ')
n, k = int(inputs[0]), int(inputs[1])
[list_of_num.remove(int(i))for i in input().split(' ')]

if len(str(n)) == sum([1 for i in list(str(n)) if int(i) in list_of_num]):
    print(n)
else:
    list_of_num = [str(i) for i in list_of_num]

    answer = itertools.product(str(''.join(list_of_num)), repeat=5)
    for j in answer:
        buf = int(''.join(j))
        if n < buf:
            print(buf)
            break

Submission status: Wrong Answer

Solution code:
import itertools

list_of_num = list(range(10))
inputs = input().split(' ')
n, k = int(inputs[0]), int(inputs[1])
[list_of_num.remove(int(i))for i in input().split(' ')]

if len(str(n)) == sum([1 for i in list(str(n)) if int(i) in list_of_num]):
    print(n)
else:
    list_of_num = [str(i) for i in list_of_num]

    answer = itertools.product(str(''.join(list_of_num)), repeat=10000)
    for j in answer:
        buf = int(''.join(j))
        if n < buf:
            print(buf)
            break

Submission status: Wrong Answer

Solution code:
list_of_num = list(range(10))
inputs = input().split(' ')
n, k = int(inputs[0]), int(inputs[1])
[list_of_num.remove(int(i))for i in input().split(' ')]

if list_of_num[0] == 0:
    print(n*list_of_num[1])
else:
    print(n* list_of_num[0])

Submission status: Wrong Answer

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

for i in range(N, 10**5):
	for c in str(i):
		if c in D:
			break
	else:
		print(i)
		exit()

Submission status: Wrong Answer

Solution code:
import os

if __name__ == "__main__":
    temp = input().split(" ")
    N = temp[0]
    L = int(temp[1])
    D = list(map(int, input().split(" ")))
    D.sort()
    like = []
    for i in range(0, 10):
        if D.count(i) == 0:
            like.append(i)
   
    ans = []
    for n in N:
        for l in like:
            if int(l) >= int(n):
                ans.append(l)
                break
    print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
nk=list(map(int,input().split()))
d=list(map(int,input().split()))
i=nk[0]
ans=0
while ans==0:
  flag=0
  for j in range(len(str(i))):
    if str(i)[j] in d:
      flag=1
      break
  if flag==0:
    ans=i
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
D = list(map(str,input().split()))
num = N
ans = False
while True:
    numstr = list(str(num))
    for i in range(len(numstr)):
        if numstr[i] in D:
            num += 10**(len(numstr)-1-i)
            break
        if i == len(numstr) - 1:
            ans = num
    if ans != False:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
D = list(input().split())
num = N
ans = False
while True:
    numstr = list(str(num))
    for i in range(len(numstr)):
        if numstr[i] in D:
            num += 10**(len(numstr)-1-i)
            break
        ans = num
    if ans != False:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
M=str(N)
hako=[]
for i in range(len(M)):
    hako.append(int(M[i]))
j = 0
while j < len(hako):
    if hako[j] in D:
        if j >= 1:
            if hako[j] == 9:
                hako[j] -= 9
        else:
            hako[j] += 1
    else:
        j += 1
print(*hako,sep="")

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
M=str(N)
hako=[]
for i in range(len(M)):
    hako.append(int(M[i]))
j = 0
while j < len(hako):
    if hako[j] in D:
        hako[j] += 1
    else:
        j += 1
print(*hako,sep="")

Submission status: Wrong Answer

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

l = [0,1,2,3,4,5,6,7,8,9]

for i in range(len(D)):
    l.remove(D[i])
l = set(l)

for n in range(N,10000,1):
    j = set(list(map(int, list(str(n)))))
    if l>=j:
        print(n)
        break

Submission status: Wrong Answer

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

l = [0,1,2,3,4,5,6,7,8,9]

for i in range(len(D)):
    l.remove(D[i])
l = set(l)

for n in range(N,10000,1):
    j = set(list(map(int, list(str(n)))))
    if l==j:
        print(n)
        break

Submission status: Wrong Answer

Solution code:
from itertools import product

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

for i in range(n,10000):
  flag=True
  tmp = i
  while True:
    if (tmp % 10) in dd:
      flag = False
    tmp = tmp//10
    if tmp<=0 :
      break
  if flag:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product

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

for i in range(n,10000):
  flag=True
  tmp = i
  while tmp>0:
    if (tmp % 10) in dd:
      flag = False
    tmp = tmp//10
  if flag:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product

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

figs = list(map(str, list(set(range(10)) - set(dd))))

a = list(product(figs, figs, figs, figs))
a = sorted([int(''.join(v)) for v in a])
  
ans = 0
for ai in a:
  if ai >= n:
    ans = ai
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

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

figs = list(map(str, list(set(range(10)) - set(dd))))

a = list(product(figs, figs, figs, figs))
a = [int(''.join(v)) for v in a]

ans = 0
for ai in a:
  if ai >= n:
    ans = ai
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
E = [x for x in range(10) if x not in D]
# print(N, K, D, E)

def is_valid(n, d):
    q = (n % (10 ** d)) // (10 ** (d - 1))
    # print(n, d, q)
    return q in E

ans = N
d = 1
while d <= len(str(N)):
    if is_valid(ans, d):
        d += 1
    else:
        ans += 10**(d - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
E = [x for x in range(10) if x not in D]
# print(N, K, D, E)

def is_valid(n, d):
    q = (n // (10 ** d)) % 10
    # print(q)
    return q in E

ans = N
d = 1
while d < len(str(N)):
    if is_valid(ans, d):
        d += 1
    else:
        ans += 10**(d - 1)

print(ans)

Submission status: Wrong Answer

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

i =1
while True:
  if 10**(i-1)>n:
    break
  #i桁目の数字を取得
  tmp = (n%(10**i))//(10**(i-1))
  if tmp not in d:
    i+= 1
    continue
  else:
    n+=10**(i-1)
print(n)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
use = [str(i) for i in range(10) if i not in d]
mon = [int(i+j+k+l+m) for i in use for j in use for k in use for l in use for m in use if int(i+j+k+l+m)>=n]
print(min(mon))

Submission status: Wrong Answer

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

set_num = set()
for i in range(10):
    set_num.add(i)

set_use_num = set_num - set_D
set_use_num = sorted(set_use_num)

str_n = str(n)
len_n = len(str_n)
for j in range(5-len_n):
    str_n = '0' + str_n

# 10000の位からcheck
digit_count = 0
Ans_num = [0,0,0,0,0]

for num in str_n:
    digit_count += 1
    check = False
    for use_num in set_use_num:
        if use_num >= int(num):
            Ans_num[digit_count - 1] = use_num
            check = True
            break
    if check == False:
        Ans_num[digit_count - 2] += 1
        Ans_num[digit_count - 1] = min(set_use_num)

ans = 0
for i in range(5):
    ans += Ans_num[4-i] * (10**(i))
    if ans >= n:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N, K = list(map(int, input().split()))
D = set(input().split())
diff = set([str(n) for n in range(10)]) - D
lenN = len(str(N)) + 1

lists = list(itertools.product(list(diff), repeat=lenN))
lists = sorted([int("".join(l)) for l in lists])

for l in lists:
  if l >= N:
    print(l)
    break

Submission status: Wrong Answer

Solution code:
import itertools

N, _ = list(map(int, input().split()))
D = set(input().split())
diff = set([str(n) for n in range(10)]) - D
lenN = len(str(N))

lists = list(itertools.product(list(diff), repeat=lenN))
lists = sorted([int("".join(l)) for l in lists])

for l in lists:
  if l >= N:
    print(l)
    break

Submission status: Wrong Answer

Solution code:
N,K=(int(x) for x in input().split())
dis_list=(input().split())
price_list=range(N,10000)
dis_count=0
for price in price_list:
  dis_count=0
  for i in dis_list:
    if i in str(price):
      dis_count+=1
  if dis_count==0:
    print(price)
    break

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=set(int(x) for x in input().split())
T=set(range(10))-D
answer=100000

for x in itertools.product(T,repeat=5):
    p=0
    for i in range(5):
      p +=x[i]*10**i
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
answer=100000
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=5):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000+x[-5]*10000
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
answer=float('inf')
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=5):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000+x[-5]*10000
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
answer=10000
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=5):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000+x[-5]*10000
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
answer=10000
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=4):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
answer=10000
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=4):
  for i in range(5):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000
    if p>=N:
      answer=min(p,answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=[int(x) for x in input().split()]
T=[]
for i in range(10):
  if not i in D:
    T+=[i]
for x in itertools.product(T,repeat=5):
  answer=0
  for i in range(5):
    p=x[-1]+x[-2]*10+x[-3]*100+x[-4]*1000+x[-5]*10000
    if p>=N:
      print(p)
      exit()

Submission status: Wrong Answer

Solution code:
### N = int(input(())
N, M = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N, 10000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)

Submission status: Wrong Answer

Solution code:
### N = int(input(())
N, M = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N, 10000):
    if i % 10 in D:
        continue
    if (i / 10) % 10 in D:
        continue
    if (i / 100) % 10 in D:
        continue
    if int(i / 1000) in D:
        continue
    break

if i > 9999:
    print(0)
else:
    print(i)

Submission status: Wrong Answer

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

print(N)

Submission status: Wrong Answer

Solution code:
money, num = map(str, input().split())
hate = list(map(str, input().split()))

for i in range(int(money), 10001):

    a = [hate_num for hate_num in hate if hate_num in str(i)]
    if a == []:
        print(str(i))
        break

Submission status: Wrong Answer

Solution code:
money, num = map(str, input().split())
hate = list(map(str, input().split()))

for i in range(int(money), 10000):

    a = [hate_num for hate_num in hate if hate_num in str(i)]
    if a == []:
        print(str(i))
        break

Submission status: Wrong Answer

Solution code:
def problem_c():
    N, K = map(int, input().split())
    D = list(map(str, input().split()))
    numbers = [str(i) for i in range(10)]
    availables = set(numbers) - set(D)

    for i in range(N, 10000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return

# numbers = {str(i) for i in range(10)}
# N, K = map(int, input().split())
# *D, = map(str, input().split())
# D = set(D)
# available = numbers - D
# ans = 0
# for i in range(N, 100000):
#     nums = set(str(i))
#     if nums <= available:
#         print(i)
#         break

##########
problem_c()

Submission status: Wrong Answer

Solution code:
def problem_c():
    N, K = map(int, input().split())
    D = map(str, input().split())
    numbers = [str(i) for i in range(10)]
    availables = set(numbers) - set(D)

    for i in range(N, 10000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return


##########
problem_c()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = map(str, input().split())
numbers = {str(i) for i in range(10)}
availables = set(numbers) - set(D)

for i in range(N, 10000):
    nums = set(str(i))
    if nums <= availables:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def problem_c():
    # N, K = map(int, input().split())
    N, K = map(int, input().split())
    D = map(str, input().split())
    numbers = {str(i) for i in range(10)}
    availables = set(numbers) - set(D)

    for i in range(N, 10000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return


##########
problem_c()

Submission status: Wrong Answer

Solution code:
price, n = map(int, input().split())
hate = list(map(int, input().split()))
like = set(range(10)) - set(hate)

keta = len(str(price))-1
_price = [int(i) for i in str(price)]

if set(_price) <= set(like):
    print(price)
else:
    for i in sorted(like):
        if i > int(_price[0]):
            print(str(i) + ''.join(str(min(like)) * keta))

Submission status: Wrong Answer

Solution code:
N, K = [int(i) for i in input().split()]
dl = [int(i) for i in input().split()]
D = [1 if i not in dl else 0 for i in range(10)]
D = D + D[:1]
n = str(N)[::-1]
ans = []
add = 0
for a in range(len(n)):
    try:
        num = D.index(1, int(n[a])+add)
        ans.append(num%10)
        if num == 10:
            add = 1
        else:
            add = 0
    except:
        add = 1
        ans.append(D.index(1))
if add == 1:
    ans.append(D.index(1,add))
# print(D)
print("".join(map(str, ans[::-1])))

Submission status: Wrong Answer

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

if len(list(a)) == 0:
    print(0)

for i in range(n, 10000):
    x = list(str(i))
    flag = True
    for j in x:
        if int(j) in a:
            continue
        else:
            flag = False
            break
    if flag is True:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
one_to_nine = set([0,1,2,3,4,5,6,7,8,9])
a = set(list(map(int, input().split())))
a = one_to_nine - a
a = list(a)
a.sort()

for i in range(n, 10001):
    x = list(str(i))
    flag = True
    for j in x:
        if int(j) in a:
            continue
        else:
            flag = False
            break
    if flag is True:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(10)) ^ set(D)
length = len(str(N))
print(like_num)
for i in range(length, length+2):
  for x in product(like_num,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=N:
          print(d)
          exit()

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(0,10)) ^ set(D)
length = len(str(N))

comb = [int("".join(map(str, a))) for a in product(like_num, repeat=length+1)]
ind = bisect.bisect_left(comb, N)
print(comb[ind])

Submission status: Wrong Answer

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

for i in range(n, 10*n+1):
    num = list(str(i))
    for j, n in enumerate(num):
        print(n)
        if n in d:
            break
        if j == len(num)-1:
            print(i)
            exit()

Submission status: Wrong Answer

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

for i in range(n, 10*n+1):
    num = list(str(i))
    for n in num:
        if n in d:
            break
        print(i)
        exit()

Submission status: Wrong Answer

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

for i in range(n, 10**5):
    num = list(str(i))
    for n in num:
        if n in d:
            break
        print(i)
        exit()