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:
#!/usr/bin/env python3
# 全探索だが、Nを超える場合があるので注意
n,k = map(int,input().split())
s = str(n)
d = list(map(int,input().split()))
#すでにsortされている
convert = [0]*10 # convert[i] はi 以上で使える数字ないなら10
for j in range(10):
    i = j
    while True:
        if i not in d: break
        elif i == 10: 
            break
        else: i += 1
    convert[j] = i
#print(convert,d)
min_use = min(convert)#最小の使えるやつ
kuriagari = 0
out = ""
for i in range(len(s)):#１の位から見ていく
    digit = kuriagari + int(s[-1-i])
    if digit >= 10 or convert[digit] == 10:
        out = str(min_use)+out
        kuriagari = 1
    else:
        out = str(convert[digit]) + out
        kuriagari = 0
print(out)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n,k = map(int,input().split())
s = str(n)
d = list(map(int,input().split()))
for i in range(n,10000):
    # i の中にd に含めれるものがないか１つづつ見ていく
    str_i = str(i)
    ok = 1
    for j in str_i:
        if int(j) in d:
            ok = 0
            break
    if ok:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def keta(n):
    cnt = 0
    while(n > 0):
        cnt += 1
        n = n//10
    
    return cnt

n, k = list(map(str, input().split()))
flag = 0
d = [i for i in input().split()]

for i in n:
    if i in d:
        flag += 1

if flag:
    n = int(n)
    tmp = []
    for i in range(10):
        if str(i) not in d:
            tmp.append(i)
    if tmp[0] == 0:
      print(tmp[1], end="")
    else:
      print(tmp[0], end="")
    
    for i in range(keta(n)-1):
      print(tmp[0], end="")
    
else:
    ans = int(n)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
count=0

for i in range(n,10001):
  for j in range(len(str(i))):
    if str(i)[j] in str(d):
      break
      
    else:
      count+=1
      
  if count==len(str(i)):
    print(i)
    sys.exit()
  count=0

Submission status: Wrong Answer

Solution code:
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
count=0

for i in range(n,10001):
  for j in range(len(str(i))):
    if str(i)[j] in str(d):
      break
      
    else:
      count+=1
      
  if count==len(str(i)):
    print(i)
    sys.exit()

Submission status: Wrong Answer

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

while True:
    for s in str(N):
        if s in D:
            N+=1
            break
    else:
        print(N)
        exit()

Submission status: Wrong Answer

Solution code:
from collections import deque

N,K=map(int,input().split())
D=list(map(int,input().split()))
like=list(range(1,10))
dislike0=False

for s in D:
    if s==0:
        dislike=True
    else:
        like.remove(s)

like.sort()
q=deque(like)

if not dislike0:
    like.insert(0,0)

while q:
    num=q.popleft()

    if num>=N:
        print(num)
        exit()
    for i in range(len(like)):
        q.append((int(str(num)+str(like[i]))))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8-*-
strs = []
n,k = map(int,input().split())
hates = list(input().split())

give = n

while(True):
  stri = str(give)
  for hate in hates:
    if hate in stri:
      give = give + 1
      break
    else:
      print(give)
      exit()

Submission status: Wrong Answer

Solution code:
import itertools
n,k = map(int,input().split())
unlike = list(map(int,input().split()))
like = []
for i in range(0,10):
    if not(i in unlike):
        like.append(i)
if unlike == [0]:
    print(n)
    exit()
i = 1
ans = 0
while(i < 99):
    current = list(itertools.product(like,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if n < h:
            print(h)
            exit()
    i += 1

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set([i for i in range(10)]) - set(map(int, input().split()))
D = sorted(list(D))

def dfs(i):
    i = str(i)
    if int(i)>=n:
        return int(i)
    for d in D:
        return dfs(i+str(d))

def dfs_(i):
    i = str(i)
    if int(i)>=n:
        return int(i)
    for d in D[::-1]:
        return dfs_(i+str(d))

if D[0] == 0:
    print(min(dfs(D[1]),dfs_(D[-1])))
else:
    print(min(dfs(D[0]), dfs_(D[-1])))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set([i for i in range(10)]) - set(map(int, input().split()))
D = sorted(list(D))

def dfs(i):
    i = str(i)
    if int(i)>=n:
        return int(i)
    for d in D:
        return dfs(i+str(d))

def dfs_(i):
    i = str(i)
    if int(i)>=n:
        return int(i)
    for d in D[::-1]:
        return dfs_(i+str(d))

if D[0] == 0:
    print(dfs(D[1]))
else:
    print(min(dfs(D[0]), dfs_(D[-1])))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set([i for i in range(10)]) - set(map(int, input().split()))
D = sorted(list(D))

def dfs(i):
    if int(i)>=n:
        return print(i)
    for d in D:
        return dfs(i+str(d))

if D[0] == 0:
    dfs(str(D[1]))
else:
    dfs(str(D[0]))

Submission status: Wrong Answer

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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
line1 = input().split(' ')
N = line1[0]
D = input().split(' ')
i = -1
while i > -len(N)-1:
    while (N[i] in D[:int(line1[1])]):
        j = abs(i)
        k = (10**(j-1))
        N = str(int(N)+k)
    i -= 1
print(N)

Submission status: Wrong Answer

Solution code:
line1 = input().split(' ')
N = line1[0]
D = input().split(' ')
i = -1
while i > -len(N)-1:
    while (N[i] in D):
        j = abs(i)
        k = (10**(j-1))
        N = str(int(N)+k)
    i -= 1
print(N)

Submission status: Wrong Answer

Solution code:
line1 = input().split(' ')
N = line1[0]
D = input().split(' ')
# print(D)
i = -1
while i > -len(N)-1:
    # print("here")
    while (N[i] in D):
        j = abs(i)
        k = 1
        while j > 1:
            k *= 10
            j -= 1
        N = str(int(N)+k)
    i -= 1
print(N)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
List = list(input().split())
Digit = ['0','1','2','3','4','5','6','7','8','9']
for item in List:
  Digit.remove(item)
for i in range(N,10001):
  fig = list(str(i))
  figs = set(fig)
  if figs <= set(Digit):
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    digit = False
    for i in range(len(t[0])):
        if digit:
            break
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) == v:
                ans[-1] = j
                break
            elif int(t[0][i]) < v:
                ans[-1] = j
                for m in range(i + 1, len(t[0])):
                    ans.append(0)
                digit = True
                break

    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    if ind > 0:
        ans_s.append(-1)
    ans_s.reverse()
    if like[ans_s[0]] < int(t[0][0]) and len(ans_s) == 1:
        ans_s.append(0)
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    digit = False
    for i in range(len(t[0])):
        if digit:
            break
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) == v:
                ans[-1] = j
                break
            elif int(t[0][i]) < v:
                ans[-1] = j
                for m in range(i + 1, len(t[0])):
                    ans.append(0)
                digit = True
                break

    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    if ind > 0 or (like[ans_s[0]] < int(t[0]) and len(ans_s) == 1):
        ans_s.append(-1)
    ans_s.reverse()
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    digit = False
    for i in range(len(t[0])):
        if digit:
            break
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) == v:
                ans[-1] = j
                break
            elif int(t[0][i]) < v:
                ans[-1] = j
                for m in range(i + 1, len(t[0])):
                    ans.append(0)
                digit = True
                break

    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    if ind > 0:
        ans_s.append(-1)
    ans_s.reverse()
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []

    for i in range(len(t[0])):
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) <= v:
                ans[-1] = j
                break
    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    if ind > 0:
        ans_s.append(-1)
    ans_s.reverse()
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    for i in range(len(t[0])):
        for v in like:
            if int(t[0][i]) <= v:
                ans.append(str(v))
                break
    print(''.join(ans))




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def check(array, string):
    for i in array:
        if i in string:
            return False
    return True

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

for i in range(1, 10001):
    if check(D, str(i)) and i >= N:
        print(i)
        exit(0)

Submission status: Wrong Answer

Solution code:
def check(array, string):
    for i in array:
        if i in string:
            return False
    return True

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

numbers = [i for i in range(1, 10001) if check(D, str(i))]

for num in numbers:
    if num >= N:
        print(num)
        break

Submission status: Wrong Answer

Solution code:
x,k=open(0);m=set("1234567890")^set(k.split());n,_=map(int,x.split())
def d(i,s):
 if i: return min([d(i-1,s+j)for j in m])
 else: return 1e5 if int(s)<n else int(s)
print(d(4,""))

Submission status: Wrong Answer

Solution code:
n = input().split()[0][::-1]
d = [int(i) for i in input().split()]
e = [i for i in range(10) if i not in d]
a = ""
c = 0
for i in n:
    for j in e:
        if j >= c + int(i):
            a += str(j)
            c = 0
            break
    else:
        a += "0"
        c = 1
if c > 0:
    a += str(c)
print(a[::-1])

Submission status: Wrong Answer

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

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans+=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
amount, num_cnt = map(int, input().split())
hate_list = list(map(int, input().split()))
num_list = []
for i in range(10):
    if not i in hate_list:
        num_list.append(i)

payment = ""
for i in range(len(str(amount))):
    min_list = [k for k in num_list if k >= int(str(amount)[i])]
    if len(min_list) > 0:
        min_num = min(min_list)
        payment = payment + str(min_num)
    else:
        payment = payment + str(min(num_list))

print(payment)

Submission status: Wrong Answer

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

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    cnt+=1
print(ans)

Submission status: Wrong Answer

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

num=[]
for i in range(10):
    if i not in d:
        num.append(str(i))
#print(num)

digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>int(i):continue
        if int(ns[cnt])==int(i):
            ans+=i
            break
        else:
            ans+=i+(digit-cnt-1)*num[0]
            cnt=digit
            break
    cnt+=1
print(ans)

Submission status: Wrong Answer

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

num=[]
for i in range(10):
    if i not in d:
        num.append(str(i))
#print(num)

digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>int(i):continue
        if int(ns[cnt])==int(i):
            ans+=i
            break
        else:
            ans+=i+(digit-1)*num[0]
            cnt=digit
            break
    cnt+=1
print(ans)

Submission status: Wrong Answer

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

num=[]
for i in range(10):
    if i not in d:
        num.append(str(i))
#print(num)

digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if ns[cnt]>i:continue
        if ns[cnt]==i:
            ans+=i
        else:
            ans+=i+(digit-1)*num[0]
            cnt=digit
            break
    cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
d = [int(i) for i in input().split()]

num = [i for i in range(10)]
tmp = []
for i in num:
    if not i in d:
        tmp.append(str(i))

tmp.sort()
b = str(n)
ans = ''
count = 0

if len(set(b)) == 1 and b[0] == '9' and 9 in d:
    b = '1' + '0' * len(b)
    #print(b)

for i in range(len(b)):
    for j in tmp:
        if b[i] == j:
            ans += j
            count += 1
            break
        elif b[i] < j:
            ans += j
            count += 1
            ans += tmp[0] * (len(b) - count)
            print(ans)
            exit()
print(ans)

Submission status: Wrong Answer

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

for i in range(10001):
    S = set(list(str(N)))
    if not D & S:
        break
    N += 1

print(N)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
d = [int(i) for i in input().split()]

num = [i for i in range(10)]
tmp = []
for i in num:
    if not i in d:
        tmp.append(str(i))

tmp.sort()
#print(tmp)
#a = n // 10 #nの桁数
b = str(n)
ans = ''
count = 0
for i in range(len(b)):
    for j in tmp:
        if b[i] == j:
            ans += j
            count += 1
            break
        elif b[i] < j:
            ans += j
            count += 1
            ans += tmp[0] * (len(b) - count)
            print(ans)
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
d = [int(i) for i in input().split()]

num = [i for i in range(10)]
tmp = []
for i in num:
    if not i in d:
        tmp.append(str(i))

tmp.sort()
#print(tmp)
#a = n // 10 #nの桁数
b = str(n)
ans = ''
for i in range(len(b)):
    for j in tmp:
        if b[i] == j:
            ans += j
            break
        elif b[i] < j:
            ans += j
            #flag = 'B'
            ans += tmp[0] * (len(str(b)) - 1)
            print(ans)
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n, k = map(int,input().split())
d = [int(i) for i in input().split()]

num = [i for i in range(10)]
tmp = []
for i in num:
    if not i in d:
        tmp.append(str(i))

tmp.sort()
#print(tmp)
#a = n // 10 #nの桁数
b = str(n)
ans = ''
for i in b:
    for j in tmp:
        if i <= j:
            ans += j
            break
print(ans)

Submission status: Wrong Answer

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

while True:
    print(set(str(N)))
    if set(str(N)) >= num:
        ans = N
        break
    else:
        N += 1
print(ans)

Submission status: Wrong Answer

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

while True:
    print(set(str(N)))
    if set(str(N)) == num:
        ans = N
        break
    else:
        N += 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(10001):
    if i < n:
        continue
    i1 = str(i)
    flag = True
    for j in range(len(i1)):
        if not flag:
            break
        i2 = int(i1[j])
        if i2 in d:
            flag = False
    if not flag:
        continue
    print(i)
    break

Submission status: Wrong Answer

Solution code:
import functools

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

for i in range(n,n*11):
    l = [int(x) for x in list(str(i))]
    for j in l:
        #print(j)
        if j  in d :
            break
        print( int(functools.reduce(lambda x, y: x + y, [str(x) for x in l])))
        exit()

Submission status: Wrong Answer

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

for x in range(n, 10000):
    ans = 10000
    tmp = True
    for y in str(x):
        if int(y) in d:
            tmp = False
            break
    if tmp:
        ans = min(ans,x)
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x

    

if __name__ == '__main__':
    N, K = mulinputs()
    *ds, = mulinputs()

    for n in range(N, 10000):
        nn = n
        is_ok = True
        while nn >= 1:
            num = nn % 10
            nn //= 10
            for dd in ds:
                if dd == num:
                    is_ok = False
                    break
            if not is_ok:
                break
        if is_ok:
            print(n)
            exit()

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key



__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N, K = mulinputs()
    *ds, = mulinputs()

    nds = list(filter(lambda x: x not in ds, range(10)))

    ans, idx = 0, 0
    while N >= 1:
        d = N%10
        N //=10
        dm = 10
        for dd in nds:
            if dd < d:
                continue
            dm = min(dm, dd)
        ans += dm*10**idx
        idx += 1
    print(ans)

# EOF

Submission status: Wrong Answer

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

antilist = list(set([0,1,2,3,4,5,6,7,8,9]) - (dlist))

res = []

digit = len(str(n))

exceeded = False

while digit != 0:
    num = n // 10**(digit - 1) % 10
    for ant in antilist:
        if exceeded:
            # print('1')
            res.append(antilist[0])
            break
        else:
            if ant == num:
                # print('2')
                res.append(ant)
                break
            if ant > num:
                # print('3')
                res.append(ant)
                exceeded = True
                break
        if ant == antilist[-1]:
            if len(str(n)) == 1:
                n = 10
                break
            else:
                exceeded = False
                strn = '1' + '0'*len(str(n))
                n = int(strn)
                digit = len(str(n)) + 1
                # print(n, digit)
                break
    digit -= 1


print(''.join(map(str, res)))

Submission status: Wrong Answer

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

antilist = list(set([0,1,2,3,4,5,6,7,8,9]) - (dlist))

res = []

digit = len(str(n))

exceeded = False

while digit != 0:
    num = n // 10**(digit - 1) % 10
    for ant in antilist:
        if exceeded:
            # print('1')
            res.append(antilist[0])
            break
        else:
            if ant == num:
                # print('2')
                res.append(ant)
                break
            if ant > num:
                # print('3')
                res.append(ant)
                exceeded = True
                break
    digit -= 1


print(''.join(map(str, res)))

Submission status: Wrong Answer

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


for i in range(N,10000):
  if set(str(i)) <= OK:
    print(i)
    exit()

Submission status: Wrong Answer

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


for i in range(N,10000):
  if set(str(i)) <= OK:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
N,K = list(map(str, input().split()))
D = sorted(input().split())
W = []
P = ""
for i in range(10):
    if str(i) not in D:
        W.append(str(i))
for i in range(len(N)):
    for j in range(len(W)):
        if N[i] <= W[j]:
            P += W[j]
            break
    if i == 0 and P == "":
        if W[0] == "0":
            P = W[1] + W[0] + P
        else:
            P = W[0] + W[0] + P

print(int(P))