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:
#すべてを str型として読み込み、Kのみ int型に変換
N, Kstr = map(str, input().split()) # N: 元の数, K: NG数の数
K = int(Kstr)
D = list(map(str, input().split())) # D: NG数のリスト

# N = str(1000)
# K = 8
# D = ('1', '3', '4', '5', '6', '7', '8', '9')

def getMinimumOK():
# NGではない最小の数字を求める
    for i in range(0, 9):
        for j in range(1, K):
            if D[j - 1] == str(i):
                break
            else:
                return str(i)

def getFirstNG():
# Nの中の最初のNG数までの文字数を返す
# getFirstNG()を呼ぶ前にisOK(N)を呼んでいるので N の中に NG数 が必ず有る
    for i in range(0, len(N) - 1):
        for ng in D:
            if ng == N[i]:
                return i + 1

def isOK(number):
# NG数が含まれなければ True, 含まれていれば False を返す
    strNumber = str(number)
    strlen = len(strNumber)
    for i in range(strlen):
        if strNumber[i] in D: # i桁目の数が D の中にあれば
            return False      # number に NG数 が含まれる
    return True

def makeUpperHalf(upperHalf_org):
# 引数：最初のNG数より上位の桁の数（str型）
# 戻り値：NG数を含まない上位の数（str型）
    numUpper = int(upperHalf_org)
    while True:
        numUpper += 1
        if isOK(numUpper): # NG数が無くなるまで numUpper を増やしていく
            break
    return str(numUpper)

if isOK(int(N)): # N に　NG数 が含まれていなければ
    print(N)     # N を表示して終了
else:
    minimumOK = getMinimumOK() # 最小のOK数字（文字列型）
    firstNG = getFirstNG()     # 上位から数えて最初のNG数が出てくる桁

    upperHalf = N[:firstNG] # 先頭から最初のNG数まで
    lowerHalf = N[firstNG:] # 最初のNG数の次から末尾まで
    upper = makeUpperHalf(upperHalf)
    lower = minimumOK * len(lowerHalf) # 下半分はNGでない最小の数を桁数分、並べる
    print(upper + lower)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 環境によってはコメントに全角文字を使うとエラーが出るため

#すべてを str型として読み込み、Kのみ int型に変換
N, Kstr = map(str, input().split()) # N: 元の数, K: NG数の数
K = int(Kstr)
D = list(map(str, input().split())) # D: NG数のリスト

# N = str(1000)
# K = 8
# D = ('1', '3', '4', '5', '6', '7', '8', '9')

def getMinimumOK():
# NGではない最小の数字を求める
    for i in range(0, 9):
        for j in range(1, K):
            if D[j - 1] == str(i):
                break
            else:
                return str(i)

def getFirstNG():
# Nの中にNG数が含まれていれば 最初のNG数までの文字数を、含まれなければ -1 を返す
    for i in range(0, len(N) - 1):
        for ng in D:
            if ng == N[i]:
                return i + 1
    return -1

def isOK(number):
# NG数が含まれなければ True, 含まれていれば False を返す
    strNumber = str(number)
    for i in range(0, len(strNumber) - 1):
        for ng in D:
            if ng == N[i]:
                return False
    return True

def makeUpperHalf(upperHalf_org):
    numUpper = int(upperHalf_org)
    while True:
        numUpper += 1
        if isOK(numUpper):
            break
    return str(numUpper)

minimumOK = getMinimumOK() # 最小のOK数字（文字列型）
firstNG = getFirstNG() # 上位から数えて最初のNG数が出てくる桁

if firstNG == -1: # NG数が含まれない場合
    print(N)
else:
    upperHalf = N[:firstNG] # 先頭から最初のNG数まで
    lowerHalf = N[firstNG:] # 最初のNG数の次から末尾まで
    upper = makeUpperHalf(upperHalf)
    lower = minimumOK * len(lowerHalf) # 下位半分はNGでない最小の数を桁数分、並べる
    print(upper + lower)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
D=list(map(int,input().split()))

temp=[]
for i in range(10):
    if D.count(i)==0:
        temp.append(i)
D=temp[:]
preK=0
K=10-K

opt=D[:]
ans=10**18
for t in range(5):
    for d in D:
        for i in range(preK,K):
            if opt[i]==0:
                pass
            else:
                num=int(str(opt[i])+str(d))
                if num>=N:
                    ans=min(ans,num)
                else:
                    opt.append(num)
    preK,K=K,len(opt)        
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
D=list(map(int,input().split()))

temp=[]
for i in range(10):
    if D.count(i)==0:
        temp.append(i)
D=temp[:]
preK=0
K=10-K

opt=D[:]
ans=10**18
for t in range(4):
    for d in D:
        for i in range(preK,K):
            if opt[i]==0:
                pass
            else:
                num=int(str(opt[i])+str(d))
                if num>=N:
                    ans=min(ans,num)
                else:
                    opt.append(num)
    preK,K=K,len(opt)        
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n
print(n)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
'''
for i in range(9): 
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        if s_can_use[0] == 0:
'''
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n
print(n)

Submission status: Wrong Answer

Solution code:
import itertools
N,K=map(int,input().split())
D=set(list(map(str,input().split())))
U=list({'0','1','2','3','4','5','6','7','8','9'}^D)
U.sort()

PRD1 = list(itertools.product(U, repeat=len(str(N))))
PRD2 = list(itertools.product(U, repeat=len(str(N))+1))

import sys
for i in range(len(PRD1)):
    T=int(''.join(PRD1[i]))
    if T>=N:
        print('ans='+str(T))
        sys.exit()

for i in PRD2:
    T=int(''.join(i))
    if T>=N:
        print(T)
        sys.exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))
l = []
for i in range(10):
    if i not in D:
        l.append(i)
# print(*l)
# print(*D)
ans = N*10
for l1 in map(str, l):
    for l2 in map(str, l):
        for l3 in map(str, l):
            for l4 in map(str, l):
                tmp = int(l1+l2+l3+l4)
                if tmp >= N:
                    # print("tmp=", tmp)
                    ans = min(ans, tmp)
                    print(ans)
                    exit()
print(l[0]*(len(str(N))+1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))
l = []
for i in range(10):
    if i not in D:
        l.append(i)
# print(*l)
# print(*D)
ans = N*10
for l1 in map(str, l):
    for l2 in map(str, l):
        for l3 in map(str, l):
            for l4 in map(str, l):
                tmp = int(l1+l2+l3+l4)
                if tmp >= N:
                    # print("tmp=", tmp)
                    ans = min(ans, tmp)
                    print(ans)
                    exit()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, K = map(int, input().split())
D = list(map(int, input().split()))
l = []
for i in range(10):
    if i not in D:
        l.append(i)
ans = N*10
for l1 in map(str, l):
    for l2 in map(str, l):
        for l3 in map(str, l):
            for l4 in map(str, l):
                tmp = int(l1+l2+l3+l4)
                if tmp >= N:
                    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=sorted(list(map(int,input().split())))
ans=0
L=[i for i in range(10) if i not in D]

for i in range(N,10000):
    I=[int(j) for j in list(str(i))]
    cnt=0
    
    for j in I:
        if j not in L:
            break
        else:
            cnt+=1
    if cnt==len(I):
        ans=i
        break

print(ans)

Submission status: Wrong Answer

Solution code:
ns,k = input().split()
nlist = input().split()
answer = []
for n in ns:
    while n in nlist:
        n = int(n) + 1
        n = str(n)
    answer.append(n)

print("".join(answer))

Submission status: Wrong Answer

Solution code:
ns,k = input().split()
nlist = input().split()
answer = []
for n in ns:
    if n in nlist:
        while n in nlist:
            n = int(n) + 1
            n = str(n)
    answer.append(n)

print("".join(answer))

Submission status: Wrong Answer

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

ans = 0

for j in range(N,10*N+1):
  for k in D:
    if str(k) in str(j):
      break
    ans = j
  if ans != 0:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 10000
k = len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

Submission status: Wrong Answer

Solution code:
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 10000
k = len(str(N))
for i in range(k,5):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

LIMIT_N = 10000

while N < LIMIT_N:
    n_set = set(str(N))
    d_set = set([str(d) for d in dislikes])
    if n_set.isdisjoint(d_set):
        print(N)
        exit()
    N += 1

Submission status: Wrong Answer

Solution code:
from sys import exit

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

LIMIT_N = 10000

while N < LIMIT_N:
    if N != LIMIT_N - 1:
        N += 1
    n_set = set(str(N))
    d_set = set([str(d) for d in dislikes])
    if n_set.isdisjoint(d_set):
        print(N)
        exit()

Submission status: Wrong Answer

Solution code:
from sys import exit

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

LIMIT_N = 10000

while N < LIMIT_N:
    N += 1
    for i, num in enumerate(str(N), 1):
        if int(num) in dislikes:
            break
        if i == len(str(N)):
            if N == LIMIT_N:
                print(N-1)
                exit()
            else:
                print(N)
                exit()

Submission status: Wrong Answer

Solution code:
from sys import exit

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

LIMIT_N = 10000
if N == LIMIT_N - 1:
    print(N)
    exit()

while N < LIMIT_N:
    N += 1
    for i, num in enumerate(str(N), 1):
        if int(num) in dislikes:
            break
        if i == len(str(N)):
            print(N)
            exit()

Submission status: Wrong Answer

Solution code:
from sys import exit

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

while N < 10000:
    N += 1
    for i, num in enumerate(str(N), 1):
        if int(num) in dislikes:
            break
        if i == len(str(N)):
            print(N)
            exit()

print(N - 1)

Submission status: Wrong Answer

Solution code:
import string
import sys

N,K=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in D]

len_n=len(str(N))
def check(use,x):
    for i in str(x):
        if(int(i) not in use):
            return False
    return x

min_use=10
for i in use:
    if(i==0):
        continue
    elif(min_use>i):
        min_use=i
worst=min_use*(10**len_n)

for i in range(N,worst+1):
    x=check(use,i)
    if(x!=False):
        print(x)
        sys.exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
D = list(map(int,input().split()))
a = 10 
b = 10
c = 10
d = 10
e = 10
ans = 100000
for i in range(N,100000):
    if i >= 10000:
        a = i//10000
    if i >= 1000:
        b = i//1000
    if i >= 100:
        c = i//100
    if i >= 10:
        d = i//10
    e = i
    S = D.count(a) + D.count(b) + D.count(c) + D.count(d) + D.count(e)
    if S == 0:
        if ans > i:
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, D: "List[int]"):
    L = list(set([0,1,2,3,4,5,6,7,8,9])-set(D))

    for i in L:
        for j in L:
            for k in L:
                for l in L:
                    a = int("".join([str(i),str(j),str(k),str(l)]))
                    if  a>= N:
                        print(a)
                        return 


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n, k = list(map(int,(input().split(' '))))
d = set(list(map(int,(input().split(' ')))))
l = set(list(range(0,10)))

like = l -d 
#print(like)
#print(list(map(int,(str(10001)))))

for i in range(n,10001):
  #print(i)
  if like >= set(list(map(int,(str(i))))):
  #  print(list(like),list(map(int,(str(i)))))
    break

print(i)

Submission status: Wrong Answer

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

D = list(input().split())

for n in range(N + 1, 10 * N + 1):
    flag = True
    
    for i in range(len(str(n))):
        for j in range(K):
            if str(n)[i] == D[j]:
                flag = False

    if flag == True:
        print(n)
        break

if flag == False:
    print('false')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, K = map(int, input().split())
D = list(map(int, input().split()))

dd = [False]*10
for i in D:
  dd[i] = True

def get_num(number, order):
  k = int(number/ 10**order)
  return k % 10

def make_rest(num, order):
  ans = 0
  for i in range(order):
    ans += num*10**(i)
  return ans

def find_min(lis, index):
  for i in range(index+1, len(lis)):
    if(lis[i] == False):
      return i
  return -1

for i in range(10):
  if(dd[i] == False):
    min_num = i
    break;

#print(make_rest(2, 0))
#print(make_rest(2, 1))
#print(make_rest(2, 2))

n = len(str(N))
res = 0
for i in range(0, n):
  #print(i, N, res)
  num = get_num(N, i)
  if(dd[num] == False):
    res += num*10**(i)
    #print(res)
  else:
    k = find_min(dd, num)
    if(k != -1):
      res = k * 10**(i)
      res += make_rest(min_num, i)
      #print(make_rest(min_num, i), res)
    else:
      N = N - N%(10**i)
      N += 10**(i+1)
      res = 0

m = len(str(N))
if(m != n):
  num = get_num(N, n)
  if(dd[num] == False):
    res += num*10**(n)
    #print(res)
  else:
    k = find_min(dd, num)
    res = k * 10**(n)
    res += make_rest(min_num, n)
    print(make_rest(min_num, n), res)

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, K = map(int, input().split())
D = list(map(int, input().split()))

dd = [False]*10
for i in D:
  dd[i] = True

def get_num(number, order):
  k = int(number/ 10**order)
  return k % 10

def make_rest(num, order):
  ans = 0
  for i in range(order):
    ans += num*10**(i)
  return ans

def find_min(lis, index):
  for i in range(index+1, len(lis)):
    if(lis[i] == False):
      return i
  return -1

for i in range(10):
  if(dd[i] == False):
    min_num = i
    break;

#print(make_rest(2, 0))
#print(make_rest(2, 1))
#print(make_rest(2, 2))

n = len(str(N))
res = 0
for i in range(0, n+1):
  #print(i, N)
  num = get_num(N, i)
  if(dd[num] == False):
    res += num*10**(i)
    #print(res)
  else:
    k = find_min(dd, num)
    if(k != -1):
      res += k * 10**(i)
      res += make_rest(min_num, i)
      #print(make_rest(min_num, i))
    else:
      N += 10**(i+1)

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, K = input().split()
K = int(K)
D = list(map(int, input().split()))

dd = [False]*10
for i in D:
  dd[i] = True

for i in range(10):
  if(dd[i] == False):
    min_num = i
    break;
for i in range(min_num+1, 10):
  if(dd[i] == False):
    min_num2 = i
    break;

def find_min(lis, index):
  for i in range(index+1, len(lis)):
    if(lis[i] == False):
      return i
  if(min_num != 0):
    return min_num*10 + min_num
  else:
    return min_num2*10

def make_num(num, order):
  ans = 0
  for i in range(order):
    ans += num*10**i
  return ans

n = len(N)
res = 0
for i in range(n):
  if(dd[int(N[i])] == True):
    res += find_min(dd, int(N[i])) * 10**(n-1-i)
    if(i<n-1):
      res += make_num(min_num, n-1-i)
      break;
  else:
    res += int(N[i])*10**(n-1-i)

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, K = input().split()
K = int(K)
D = list(map(int, input().split()))

dd = [False]*10
for i in D:
  dd[i] = True

min_num = 0
for i in range(10):
  if(dd[i] == False):
    min_num = i
    break;

def find_min(lis, index):
  for i in range(index+1, len(lis)):
    if(lis[i] == False):
      return i
  return 10

def make_num(num, order):
  ans = 0
  for i in range(order):
    ans += num*10**(order-1)
  return ans

n = len(N)
res = 0
for i in range(n):
  if(dd[int(N[i])] == True):
    res += find_min(dd, int(N[i])) * 10**(n-1-i)
    if(i<n-2):
      res += make_num(min_num, n-2)
      break;
  else:
    res += int(N[i])*10**(n-1-i)

print(res)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
ans=[] 
for n in str(N):
    ans.append(int(n))
if 9 in D and ans[0] == 9:
  ans.insert(0,1)
  ans[1:]=[0]*(len(ans)-1)
for i in range(K):
    while D[i] in ans:
        idx=ans.index(D[i])
        if D[i] == 9:
          ans[idx]=0
          ans[idx-1]+=1
        elif idx<len(ans)-1:
            ans[idx+1:]=[0]*(len(ans)-1-idx)
            ans[idx]+=1
        else:
            ans[idx]+=1
x=0
for i in range(len(ans)):
  x+=ans[i]*10**(len(ans)-i-1)
print(x)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
D=list(map(int,input().split()))
ans=[] 
for n in str(N):
    ans.append(int(n))
for i in range(K):
    while D[i] in ans:
        idx=ans.index(D[i])
        if D[i] == 9:
            ans[idx]=0
            ans[idx-1]+=1
        elif idx<len(ans)-1:
            ans[idx+1:]=[0]*(len(ans)-1-idx)
            ans[idx]+=1
        else:
            ans[idx]+=1
x=0
for i in range(len(ans)):
  x+=ans[i]*10**(len(ans)-i-1)
print(x)

Submission status: Wrong Answer

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


def isOk(n, D):
    while n > 0:
        if n % 10 in D:
            return False
        n //= 10
    return True


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ans = 0
    for i in range(N, 10001):
        if isOk(i, D):
            print(i)
            return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def isOk(n, D):
    while n > 0:
        if n % 10 in D:
            return False
        n //= 10
    return True


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ans = 0
    for i in range(N, 10001):
        if i > K:
            if isOk(i, D):
                print(i)
                return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
all_flg = False
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
last_ans = n
while True:
    ans = list(str(n))
    flg = False
    flg_ls = [0 for i in range(len(str(n)))]
    for i, s in enumerate(str(n)):
        s = int(s)
        res = bisect.bisect_left(candidate, s)
        if flg:
            ans[i] = str(candidate[0])
        else:
            if res >= len_cand:
                flg_ls[i] = 1
            ans[i] = str(candidate[res if res < len_cand else 0])
        if s not in set_candidate:
            flg = True
    ans = int("".join(ans))
    hoge = int("".join([str(i) for i in flg_ls]) + "0")
    ans += hoge
    if ans == last_ans:
        break
    last_ans = ans
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
ans = list(str(n))
flg = False
flg_ls = [0 for i in range(len(str(n)))]
for i, s in enumerate(str(n)):
    s = int(s)
    res = bisect.bisect_left(candidate, s)
    if flg:
        ans[i] = str(candidate[0])
    else:
        if res >= len_cand:
            flg_ls[i] = 1
        ans[i] = str(candidate[res if res < len_cand else 0])
    if s not in set_candidate:
        flg = True
ans = int("".join(ans))
hoge = int("".join([str(i) for i in flg_ls]) + "0")
ans += hoge
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
ans = list(str(n))
flg = False
for i, s in enumerate(str(n)):
    s = int(s)
    res = bisect.bisect_left(candidate, s)
    if flg:
        ans[i] = str(candidate[0])
    else:
        ans[i] = str(candidate[res if res < len_cand else 0])
    if s not in set_candidate:
        flg = True
print("".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
ans = list(str(n))
for i, s in enumerate(str(n)):
    s = int(s)
    res = bisect.bisect_left(candidate, s)
    ans[i] = str(candidate[res if res < len_cand else 0])
print("".join(ans))

Submission status: Wrong Answer

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

cost=n
while True:
    for i in range(k):
        if str(d[i]) in str(n):
            break
        else:
            print(n)
            exit()
    n+=1

Submission status: Wrong Answer

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

cost=n
while True:
    for i in range(k):
        if str(d[i]) in str(n):
            break
        else:
            print(n)
            exit()
    n+=1

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
nums =set(input().split())
for i in range(n,10001):
    i = str(i)
    for num in nums:
        if num in i:
            break
    else:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
price, size = map(int, input().split())
dislikes = list(map(int, input().split()))
likes = list(set(range(10)) - set(dislikes))

digits = [int(digit) for digit in str(price)]
digits.insert(0, 0) # 最後に0のままだったら除いて結合する、0じゃなければそのまま結合
found = False
ok = False

if size <= 5:
    for i in range(1, len(digits)+1):
        digit = digits[-i]
        while digit < 10:
            for dis in dislikes:
                if digit == dis:
                    found = True
                    break
            if found:
                digit += 1
                found = False
            else:
                digits[-i] = digit
                break
        if digit == 10:
            digits[-i-1] += 1
            digit = 0
            while digit < 10:
                for dis in dislikes:
                    if digit == dis:
                        found = True
                        break
                if found:
                    digit += 1
                    found = False
                else:
                    digits[-i] = digit
                    break
else:
    for i in range(1, len(digits)+1):
        digit = digits[-i]
        while digit < 10:
            for like in likes:
                if digit == like:
                    ok = True                   
                    break
            if not ok:
                digit += 1
            else:
                digits[-i] = digit
                break
        if digit == 10:
            digits[-i-1] += 1
            digit = 0
            while digit < 10:
                for like in likes:
                    if digit == like:
                        ok = True                   
                        break
                if not ok:
                    digit += 1
                else:
                    digits[-i] = digit
                    break


if digits[0] == 0:
    del digits[0]

ans = int(''.join([str(num) for num in digits]))
print(ans)

Submission status: Wrong Answer

Solution code:
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # str, must reverse
isTenOver = False
for char in reversed(list(str(val))):
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if int(char) in enableList:
    isTenOver = False
    resultList.append(char)
    continue
  resultList = [str(min(enableList))] * len(resultList)
  if int(char) > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > int(char), enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(reversed(resultList)))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
zn = False
if 0 in d:
    zn = True
    d.remove(0)
nums = list(set([i for i in range(10)]) - set(d))

def dfs(s):
    if len(s) == 5:
        num = int(s)
        if num >= n:
            print(num)
            exit()
        return
    
    for dn in nums:
        if zn and dn == 0 and (0 if s == "" else int(s)) != 0: continue
        dfs(s + str(dn))

dfs("")

Submission status: Wrong Answer

Solution code:
p, _ = [int(x) for x in input().split(' ')]
v = set([str(x) for x in range(10)]) - set(input().split(' '))

for x in range(p, 10001):
  if all([s in v for s in str(x)]):
    print(x)
    break

Submission status: Wrong Answer

Solution code:
p, _ = [int(x) for x in input().split(' ')]
v = set([str(x) for x in range(10)]) - set(input().split(' '))

for x in range(p, 10000):
  if all([s in v for s in str(x)]):
    print(x)
    break

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 = 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:
    break
  else:
    num.remove(i)

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = input().split()
count = 0
for i in range(n, 10*n):
    for j in range(k):
        if d[j] in str(i):
            break
        print(i)
        count = 1
        break
    if count == 1:
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if k == 1 and l[0] == 0:
	print(n)
else:
	l1 = []
	for i in range(10):
		if i not in l:
			l1.append(i)
	l2 = []
	for i in l1:
		if i != 0:
			l2.append(i)
	t = [0 for x in range(l1.count(0))]
	l2.extend(t)
	l2 = [str(i) for i in l2]
	if int("".join(l2)) >= n:
		print("".join(l2))
	else:
		temp = "".join(l2)
		while(int(temp) < n):
			temp += temp[-1]
		print(temp)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if k == 1 and l[0] == 0:
	print(n)
else:
	l1 = []
	for i in range(10):
		if i not in l:
			l1.append(i)
	l1.sort(reverse = True)
	l2 = l1
	l2 = [str(i) for i in l2]
	if int("".join(l2)) >= n:
		print("".join(l2))
	else:
		temp = "".join(l2)
		while(int(temp) < n):
			temp += temp[-1]
		print(temp)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
all_num = [i for i in range(10)]
not_d = list(set(all_num) - set(d))
not_d.sort()
ans = []


def find_min_num(x, not_d):
    for num in not_d:
        if x <= num:
            return num
        else:
            pass


if int(str(n)[0]) not in not_d and int(str(n)[0]) < not_d[1]:
    min_num = find_min_num(x=int(str(n)[0]), not_d=not_d)
    ans.append(str(min_num))
    for i in range(len(str(n)) - 1):
        ans.append(str(0))
else:
    ans.append(str(n)[0])
    for i in range(1, len(str(n))):
        min_num = find_min_num(x=int(str(n)[i]), not_d=not_d)
        ans.append(str(min_num))
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
nd = list()
for i in range(10):
    if i not in d:
        nd.append(i)
a = n

for i in range(10000-n):
    if set([int(m) for m in list(str(a+i))]) == set(list(set([int(m) for m in list(str(a+i))]) & set(nd))):
        print(a+i)
        break

Submission status: Wrong Answer

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

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

n_st = list(str(n))
n_st = list(map(int,n_st))

ans = []
flug = False
for i in range(len(n_st)-1,-1,-1):
    for j in range(len(d)+1):
        if j < len(d):
            if n_st[i] <= d[j]:
                ans.append(d[j])
                break
        elif j == len(d):
            ans.append(d[0])
            if i+1 <= len(n_st)-1:
                n_st[i+1] += 1
            else:
                flug = True
                

if (flug):
    if d[0] != 0:
        ans.append(d[0])
    else:
        ans.append(d[1])

ttl = 0
for i in range(len(ans)):
    ttl += ans[i]*(10**i)

print(ttl)