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 = list(map(int, input().split()))
comp = [x for x in range(10)]
diff = set(comp) - set(D)
diff_list = list(diff)
diff_list.sort()
ans = []
for x in range(len(str(N))):
    for y in diff_list:
        if y >= int(str(N)[x]):
            ans.append(y)
            break
kotae = ''.join(list(map(str, ans)))
if kotae == N:
    print(int(kotae)+1)
else:
    print(kotae)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
comp = [x for x in range(10)]
diff = set(D) ^ set(comp)
diff_list = list(diff)
diff_list.sort()
ans = []
for x in range(len(str(N))):
    for y in diff_list:
        if y >= int(str(N)[x]):
            ans.append(y)
            break
kotae = ''.join(list(map(str, ans)))
if kotae == N:
    print(int(kotae)+1)
else:
    print(kotae)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
comp = [x for x in range(10)]
diff = set(D) ^ set(comp)
diff_list = list(diff)
ans = []
for x in range(len(str(N))):
    for y in diff_list:
        if y >= int(str(N)[x]):
            ans.append(y)
            break
kotae = ''.join(list(map(str, ans)))
if kotae == N:
    print(int(kotae)+1)
else:
    print(kotae)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
comp = [x for x in range(10)]
diff = set(D) ^ set(comp)
diff_list = list(diff)
ans = []
for x in range(len(str(N))):
    for y in diff_list:
        if y >= int(str(N)[x]):
            ans.append(y)
            break
print(''.join(list(map(str, ans))))

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
arr = list(input().split())
ans = 0
for i in range(N,N*N):
    flg = True
    s = str(i)
    for k in s:
        if str(k) in arr:
            flg = False
            break
    if flg:
        print(i)
        exit()

Submission status: Wrong Answer

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


valid = [i for i in range(10) if i not in d]

num = [int(i) for i in str(n)][::-1]
num.append(0)

for i in range(len(num)):
    if i == len(num)-1 and num[i] == 0:
        break
    if num[i] in d:
        if any(x in valid for x in range(num[i]+1, 10)):
            for j in range(num[i]+1, 10):
                if j in valid:
                    num[i] = j
                    break
        else:
            for j in range(0, num[i]):
                if j in valid:
                    num[i] = j
                    num[i+1] += 1
                    x = i+1
                    while num[x] == 10:
                        num[x] = 0
                        num[x+1] += 1
                        x += 1
                    break

print(int("".join(map(str, num[::-1]))))

Submission status: Wrong Answer

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

valid = [i for i in range(10) if i not in d]

num = [int(i) for i in str(n)][::-1]
num.append(0)

for i in range(len(num)-1):
    if num[i] in d:
        if any(x in valid for x in range(num[i]+1, 10)):
            for j in range(num[i]+1, 10):
                if j in valid:
                    num[i] = j
                    break
        else:
            for j in range(0, num[i]):
                if j in valid:
                    num[i] = j
                    num[i+1] += 1
                    x = i+1
                    while num[x] == 10:
                        num[x] = 0
                        num[x+1] += 1
                        x += 1
                    break

print(int("".join(map(str, num[::-1]))))

Submission status: Wrong Answer

Solution code:
n, k = input().split()
d_list = list(map(int, input().split()))
u_list = [u for u in range(10) if u not in d_list]
replace_lis = [u_list[0]] * 10
for i in range(10):
    for j in range(i,10):
        if j in u_list:
            replace_lis[i] = j
            break

n_list = list(map(int, list(n)[::-1])) + [0]

for i in range(len(n_list)):
    if n_list[i] == 10:
        n_list[i] = 0
        n_list[i + 1] += 1
    if n_list[i] > replace_lis[n_list[i]]:
        n_list[i + 1] += 1
    n_list[i] = replace_lis[n_list[i]]

result = 0
for i in range(len(n_list)):
    result += n_list[i] * (10**i)

print(result)

Submission status: Wrong Answer

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

ans=''
for i in str(N):
    while int(i) in D:
        i=str(int(i)+1)
    ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
ip = input().split()
N = int(ip[0])

K = int(ip[1])
Dinput = input().split()
Ds = []#嫌いな数
for i in range(K):
    Ds.append(Dinput[i])#文字列

boolean = False
n = N
while boolean == False:
    n += 1
    str_n = list(str(n))
    for d in range(K):
        if Ds[d] in str_n:#嫌いな文字がある場合
            boolean = False
            break
        else:
            boolean = True
    
print(n)

Submission status: Wrong Answer

Solution code:
#N,M=map(int,input().split())
#T=list(map(int,input().split()))
N=9999 
M=1
#T=[1,3,4,5,6,7,8,9]
T=[]
L=[]
for i in range(10):
    if(not T.count(i)):
        L.append(i)

l=len(str(N))+1
MIN=10**10

def calc(st):
    global MIN
    st=str(st)
    if(len(st)>l):return 0
    for num in L:
        t=calc(st+str(num))
        if(int(t)>=N):
            MIN=min(MIN,int(t))
    if(st!=""):
        if(int(st)>=N):
            MIN=min(int(st),MIN)
    return (MIN)

print(calc(str()))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
list = list(map(int, input().split()))
def keisan():
    sen = N // 1000
    hyaku = (N % 1000) // 100
    juu = (N % 100) //10
    iti = (N % 10)
    return sen,hyaku,juu,iti
sen,hyaku,juu,iti = keisan()

while(iti in list):
    N += 1
    sen,hyaku,juu,iti = keisan()
while(juu in list):
    N += 10
    sen,hyaku,juu,iti = keisan()
while(hyaku in list):
    N += 100
    sen,hyaku,juu,iti = keisan()
while(sen in list):
    N += 1000
    sen,hyaku,juu,iti = keisan()
print(N)

Submission status: Wrong Answer

Solution code:
from itertools import *

if __name__=="__main__":
    n,k = map(int,input().split(' '))
    d = list(map(int,(input().split(' '))))
    d = [i for i in range(10) if i not in d]
    ans = 1e10
    keta = len(str(n))
    for perm in product(d,repeat=keta+1):
        num = 0
        for v in perm:
            num = 10*num+v
        if n <= num and num < ans:
            ans = num
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import *

if __name__=="__main__":
    n,k = map(int,input().split(' '))
    d = list(map(int,(input().split(' '))))
    d = [i for i in range(10) if i not in d]
    ans = 1e10
    keta = len(str(n))
    for perm in product(d,repeat=keta):
        num = 0
        for v in perm:
            num = 10*num+v
        if n <= num and num < ans:
            ans = num
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in product(nm,repeat=5):
  b.append(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4])
  b.append(1000*i[0]+100*i[1]+10*i[2]+i[3])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in product(nm,repeat=5):
  b.append(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in  product(nm,repeat=5):
  b.append(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in  product(nm,repeat=4):
  b.append(1000*i[0]+100*i[1]+10*i[2]+i[3])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Submission status: Wrong Answer

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

s = list(n)

for i in range(len(s)):
    isBan = True

    while isBan:
        isBan = s[i] in nums
        if isBan:
            kazu = int(s[i]) + 1
            s[i] = str(kazu)

            # もし最後の桁でなかったらi桁目以降を0にする
            if i != len(s) - 1:
                for j in range(i + 1, len(s)):
                    s[j] = '0'
        else:
            isBan = False

print(''.join(s))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 10001):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 10000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys

def hantei(array,n):
  s = str(n)
  for i in range(len(s)):
    if s[i] in array:
      return False
  
  return True

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

while True:
  if hantei(d,n):
    print(n)
    sys.exit()
    
  n += 1

Submission status: Wrong Answer

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

for i in range(n,100000):
    for j in d:
        if str(i).find(j) >= 0:
            break
        print(i)
        sys.exit()

Submission status: Wrong Answer

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

for i in range(n,99999):
    for j in d:
        if str(i).find(j) >= 0:
            break
        print(i)
        sys.exit()

Submission status: Wrong Answer

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

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for h in num_lis:
    for i in num_lis:
        for j in num_lis:
            for k in num_lis:
                for l in num_lis:
                    a = 10000*h+1000*i + 100 *j + 10*k + l
                    if a>=N:
                        ans.append(a)
print(min(ans))

Submission status: Wrong Answer

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

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for h in num_lis:
    for i in num_lis:
        for j in num_lis:
            for k in num_lis:
                for l in num_lis:
                    a = 10000*h+1000*i + 100 *j + 10*k + l
                    if a>=N:
                        ans.append(a)
print(ans[0])

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
while 1:
  hantei=0
  for i in range(len(str(n))-1):
    #print(str(n)[i])
    if int(str(n)[i]) in d:
      hantei=1
      break
  if hantei==0:
    break
  n+=1
print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
lst=input().split()
i=n
for j in str(i):
    while "j" in lst:
         i += 1

print(i)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
L = set(input().split())
while n < 10000:
  if set(str(n)) & L == set():
    print(n)
    exit()
  n += 1

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = set(int(x) for x in input().split())
P = set(range(10)) - D
M=len(str(N))
Q=[]
for H in itertools.product(P,repeat=M):
  R=0
  for i in range(M):
    R += H[i]*(10**(M-i-1))
  if R>=N:
    print(R)
    exit()
for H in itertools.product(P,repeat=M+1):
  R=0
  for i in range(M+1):
    R += H[i]*(10**(M-i))
  if R>=N:
    print(R)
    exit()

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = set(int(x) for x in input().split())
P = set(range(10)) - D
Q=[]

for H in itertools.product(P,repeat=5):
  R=0
  for i in range(5):
    R += H[i]*(10**(4-i))
  if R>=N:
    print(R)
    exit()

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = set(int(x) for x in input().split())
P = set(range(10)) - D
Q=[]

for H in itertools.product(P,repeat=4):
  R=0
  for i in range(4):
    R += H[i]*(10**(3-i))
  if R>=N:
    print(R)
    exit()
print(10**4)

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = set(int(x) for x in input().split())
P = set(range(10)) - D
Q=[]
M =len(str(N))
for H in itertools.product(P,repeat=M):
  R=0
  for i in range(M):
    R += H[i]*(10**(M-i-1))
  if R>=N:
    print(R)
    exit()
print(10**len(str(N)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
nums = {0,1,2,3,4,5,6,7,8,9}
usable = sorted(list(nums - d))
condition = True
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                num = int(str(p) + str(q) + str(r) + str(s))
                if condition :
                    if num >= n :
                        print(num)
                        condition = False
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                for t in usable :
                    num = int(str(p) + str(q) + str(r) + str(s) + str(t))
                    if condition :
                        if num >= n :
                            print(num)
                            condition = False

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
nums = {0,1,2,3,4,5,6,7,8,9}
usable = sorted(list(nums - d))
condition = True
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                for t in usable :
                    num = int(str(p) + str(q) + str(r) + str(s) + str(t))
                    if condition :
                        if num >= n :
                            print(num)
                            condition = False
            
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                for t in usable :
                    for u in usable :
                        num = int(str(p) + str(q) + str(r) + str(s) + str(t) + str(u))
                        if condition :
                            if num >= n :
                                print(num)
                                condition = False

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
nums = {0,1,2,3,4,5,6,7,8,9}
usable = sorted(list(nums - d))
condition = True
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                for t in usable :
                    num = int(str(p) + str(q) + str(r) + str(s) + str(t))
                    if condition == True :
                        if num >= n :
                            print(num)
                            condition = False

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
nums = {0,1,2,3,4,5,6,7,8,9}
usable = sorted(list(nums - d))
condition = True
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                num = int(str(p) + str(q) + str(r) + str(s))
                if condition == True :
                    if num >= n :
                        print(num)
                        condition = False
if condition == True :
    m = min(usable)
    num = int(str(m) * 5)
    print(num)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
nums = {0,1,2,3,4,5,6,7,8,9}
usable = sorted(list(nums - d))
condition = True
for p in usable :
    for q in usable :
        for r in usable :
            for s in usable :
                num = int(str(p) + str(q) + str(r) + str(s))
                if condition == True :
                    if num >= n :
                        print(num)
                        condition = False

Submission status: Wrong Answer

Solution code:
n_k = list(map(int, input().split()))
d_list = list(map(int, input().split()))

def kuriagari(money, index):
    add_next = False
    while money[index] in d_list:
        if money[index] != 9:
            money[index] += 1
            if money[index] not in d_list:
                break
        else:
            money[index] = 0
            add_next = True

    return money, add_next

def main():
    n = n_k[0]
    k = n_k[1]

    shiharai = []

    while True:
        if n >= 10:
            shiharai.append(n % 10)
            n //= 10
        else:
            shiharai.append(n)
            break
    shiharai.append(0)

    for i in range(len(shiharai)-1):
        if shiharai[i] in d_list:
            shiharai, add_next = kuriagari(shiharai, i)
            if add_next:
                for j in range(i+1, len(shiharai)):
                    shiharai[j] = (shiharai[j] + 1) % 10
                    if shiharai[j] != 0:
                        break
    if shiharai[len(shiharai)-1] != 0:
        shiharai, _  = kuriagari(shiharai, len(shiharai)-1)

    cost = 0

    for i in range(len(shiharai)):
        cost += pow(10, i) * shiharai[i]
    print(cost)
main()

Submission status: Wrong Answer

Solution code:
n_k = list(map(int, input().split()))
d_list = list(map(int, input().split()))

def kuriagari(money, index):
    add_next = False
    while money[index] in d_list:
        if money[index] != 9:
            money[index] += 1
            if money[index] not in d_list:
                break
        else:
            money[index] = 0
            add_next = True

    return money, add_next

def main():
    n = n_k[0]
    k = n_k[1]

    shiharai = []

    while True:
        if n >= 10:
            shiharai.append(n % 10)
            n //= 10
        else:
            shiharai.append(n)
            break
    shiharai.append(0)

    for i in range(len(shiharai)):
        if shiharai[i] in d_list:
            shiharai, add_next = kuriagari(shiharai, i)
            if add_next:
                for j in range(i+1, len(shiharai)):
                    shiharai[j] = (shiharai[j] + 1) % 10
                    if shiharai[j] != 0:
                        break

    cost = 0
    for i in range(len(shiharai)):
        cost += pow(10, i) * shiharai[i]
    print(cost)
main()

Submission status: Wrong Answer

Solution code:
n_k = list(map(int, input().split()))
d_list = list(map(int, input().split()))

def kuriagari(money, index):
    add_next = False
    while money[index] in d_list:
        if money[index] != 9:
            money[index] += 1
            if money[index] not in d_list:
                break
        else:
            money[index] = 0
            add_next = True

    return money, add_next

def main():
    n = n_k[0]
    k = n_k[1]

    shiharai = []

    while True:
        if n >= 10:
            shiharai.append(n % 10)
            n //= 10
        else:
            shiharai.append(n)
            break
    shiharai.append(0)

    for i in range(len(shiharai)-1):

        if shiharai[i] in d_list:
            shiharai, add_next = kuriagari(shiharai, i)
            if add_next:
                for j in range(i+1, len(shiharai)):
                    shiharai[j] = (shiharai[j] + 1) % 10
                    if shiharai[j] != 0:
                        break

    cost = 0
    for i in range(len(shiharai)):
        cost += pow(10, i) * shiharai[i]
    print(cost)
main()

Submission status: Wrong Answer

Solution code:
n_k = list(map(int, input().split()))
d_list = list(map(int, input().split()))

def kuriagari(money, index):
    add_next = False
    while True:
        if money[index] != 9:
            money[index] += 1
            if money[index] not in d_list:
                break
        else:
            money[index] = 0
            add_next = True

    return money, add_next

def main():
    n = n_k[0]
    k = n_k[1]

    shiharai = []

    while True:
        if n >= 10:
            shiharai.append(n % 10)
            n //= 10
        else:
            shiharai.append(n)
            break
    shiharai.append(0)

    for i in range(len(shiharai)-1):

        if shiharai[i] in d_list:
            shiharai, add_next = kuriagari(shiharai, i)
            if add_next:
                for j in range(i+1, len(shiharai)):
                    shiharai[j] = (shiharai[j] + 1) % 10
                    if shiharai[j] != 0:
                        break

    cost = 0
    for i in range(len(shiharai)):
        cost += pow(10, i) * shiharai[i]
    print(cost)
main()

Submission status: Wrong Answer

Solution code:
n_k = list(map(int, input().split()))
d_list = list(map(int, input().split()))

def kuriagari(money, index):
    add_next = False
    while True:
        if money[index] != 9:
            money[index] += 1
            if money[index] not in d_list:
                break
        else:
            money[index] = 0
            add_next = True
    if add_next:
        kuriagari(money, index+1)
    return money

def main():
    n = n_k[0]
    k = n_k[1]

    shiharai = []

    while True:
        if n >= 10:
            shiharai.append(n % 10)
            n //= 10
        else:
            shiharai.append(n)
            break
    shiharai.append(0)

    for i in range(len(shiharai)-1):

        if shiharai[i] in d_list:
            shiharai = kuriagari(shiharai, i)
    cost = 0
    for i in range(len(shiharai)):
        cost += pow(10, i) * shiharai[i]
    print(cost)
main()

Submission status: Wrong Answer

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0]] + N[i+1:]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i] = nums[j]
  #print(i,N)
  i -= 1
print(''.join([str(n) for n in N]))
#print(N)

Submission status: Wrong Answer

Solution code:
import bisect, copy

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N_tail = copy.deepcopy(N[i+1:])
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0]] + tmp_N_tail
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i] = nums[j]
  #print(i,N)
  i -= 1
print(''.join([str(n) for n in N]))
#print(N)

Submission status: Wrong Answer

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)

if len(nums) == 0:
  print(''.join([str(n) for n in N]))
  exit()

nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Wrong Answer

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)

if len(nums) == 0:
  print(''.join([str(n) for n in N]))
  exit()

nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0]]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      j = j if j != -1 else 0
      N[i] = nums[j]
  i -= 1
print(''.join([str(n) for n in N]))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  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)
          return 0
solve()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+3):
    if i >= N:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in D:
          break
        else:
          print(i)
          return 0
solve()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+1):
    if i >= N:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in D:
          break
        else:
          print(i)
          return 0
solve()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N):
    if i >= N:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in D:
          break
        else:
          print(i)
          return 0
solve()

Submission status: Wrong Answer

Solution code:
import sys
n = list(map(int, input().split()))
N = n[0]
K = n[1]

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

total2 = 0
num = [i for i in range(10)]
for i in d:
    num.remove(i)

for n in num:
  total = N*n
  tl    = list(str(total))
  for i in d:
    total2 = total if tl.count(i) == 0 else 0
          
print(total2)

Submission status: Wrong Answer

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

for i in range(N,10000):
  j=0
  si=list(str(i))
  for k in si:
    if int(k) in D:
      j=1
  if j==0:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
import bisect

n,k = map(int, input().split())
d = list(map(int, input().split()))
num = [ i for i in range(10)]
num += d
a = [ x for x in set(num) if num.count(x)<2]
s = str(n)
m = len(s)
ans = []
for i in range(m):
    x = int(s[i])
    index = bisect.bisect_left(a,x)
    if index>len(a)-1:
        if a[0]==0:
            ans.append(str(a[1]))
        else:
            ans.append(str(a[0]))
        for j in range(m-i):
            ans.append(str(a[0]))
        break
    elif a[index]==x:
        ans.append(str(x))
    else:
        ans.append(str(a[index]))
        for j in range(m-i-1):
            ans.append(str(a[0]))
        break
print("".join(ans))

Submission status: Wrong Answer

Solution code:
n = list(map(int, input().split()))
N = n[0]
K = n[1]

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

num = [i for i in range(1,10)]
for i in d:
  if i == 0:
    continue
  else:
    num.remove(i)

total = N*min(num)
print(total)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = set(map(int,input().split()))
list_N = list(str(N))
len_N = len(list_N)
list_N = [int(list_N[i]) for i in range(len_N)]
ans = []
for i in range(len_N):
  for j in range(K):
    if list_N[i] in D:
      list_N[i] += 1
    else:
      ans.append(list_N[i])
      break
print("".join(list(map(str,ans))))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
li_n = list(map(int, input().split()))
for i in range(N, 10000):
  if len(set(li_n)&set([int(y) for y in str(i)])) == 0:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,10001):
    if use >= set(str(i)):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,10000):
    if use >= set(list(str(i))):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,10000):
    if use >= set(str(i)):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
use = [0,1,2,3,4,5,6,7,8,9]
Keta = []
Keta.append(N // 1000)
Keta.append(N % 1000 // 100)
Keta.append(N % 1000 % 100 // 10)
Keta.append(N % 1000 % 100 % 10)
#print("Keta is {}".format(Keta))
Keta_Min = []

def normal(N):
    for i in range(len(D)):
        use.remove(D[i])
    #print("use is {}".format(use))
    for i in range(4):
        A = []
        for j in range(len(use)):
            if Keta[i] <= use[j]:
                A.append(use[j])
        #print(i,A)
        if A == []:
            A.append(0)
        Keta_Min.append(min(A))
    Answer = 0
    Answer = Keta_Min[0] * 1000 + Keta_Min[1] * 100 + Keta_Min[2] * 10 + Keta_Min[3]
    print(Answer)

normal(N)

Submission status: Wrong Answer

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

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    return 10 * x

answer = F(N)
print(answer)