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:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    d = na()

    s_n = str(n)

    i = 0
    while i < len(str(s_n)):
        current_num = int(s_n[-1 - i])
        while current_num in d:
            n += 10 ** i
            s_n = str(n)
            current_num = int(s_n[-1 - i])
        i += 1

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    d = na()

    s_n = str(n)
    l = len(s_n)
    
    i = 0
    while i < l:
        current_num = int(s_n[-1 - i])
        while current_num in d:
            n += 10 ** i
            current_num = (current_num + 1) % 10
        s_n = str(n)
        l = len(s_n)
        i += 1

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    d = na()

    s_n = str(n)

    i = 0
    while i < len(s_n):
        current_num = int(s_n[-1 - i])
        while current_num in d:
            n += 10 ** i
            current_num = (current_num + 1) % 10
        s_n = str(n)
        i += 1

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    d = na()

    s_n = str(n)

    for i in range(len(s_n)):
        current_num = int(s_n[-1 - i])
        while current_num in d:
            n += 10 ** i
            current_num = (current_num + 1) % 10
        s_n = str(n)

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a=[int(i) for i in input().split()]
b=[0,1,2,3,4,5,6,7,8,9]
for i in a:
  if i in b:
    b.remove(i)
c=[]
for i in str(N):
  if int(i) in b:
    c.append(int(i))
  else:
    for j in b: 
      if j > int(i):
        c.append(j)
        break
if len(c) > 0: 
  d=[str(i) for i in c]
  ans="".join(d)
else:
  for i in range(len(str(N))+1):
    c.append(b[0])
  if c[0]==0:
    c[0]=b[1]
  d=[str(i) for i in c]
  ans="".join(d)
print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
a=[int(i) for i in input().split()]
b=[0,1,2,3,4,5,6,7,8,9]
for i in a:
  if i in b:
    b.remove(i)
c=[]
for i in str(N):
  if int(i) in b:
    c.append(int(i))
  else:
    for j in b: 
      if j > int(i):
        c.append(j)
        break
d=[str(i) for i in c]
ans="".join(d)
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(str,input().split(' '))
 
D = set(map(str,input().split(' ')))
 
n=set(map(str,D))
 
ans = ''
 
t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - n)))
t.append(0)
t.sort()
 
for i in N:
    for j in t:
        if j >= int(i):
            ans+=str(j)
            break
if ans and int(ans) >= int(N):
    print(ans)
else:
    print(str(t[1])+'0'*(len(N)))

Submission status: Wrong Answer

Solution code:
N, K = map(str,input().split(' '))
D = set(map(str,input().split(' ')))
ans = ''
t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - D)))
t.append(0)
t.sort()
if N[0] in t:
    for i in N:
        ans2 = ans
        for j in t:
            if j >= int(i):
                ans+=str(j)
                break
        if ans2 == ans:
            ans+='0'
else:
    ans+=str(t[1]) +'0'*(len(N)-1)
if int(ans) >= int(N):
    print(ans)
else:
    print(ans+'0')

Submission status: Wrong Answer

Solution code:
N, K = map(str,input().split(' '))
D = set(map(str,input().split(' ')))
ans = ''
t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - D)))
t.append(0)
t.sort()
if N[0] in t:
    for i in N:
        ans2 = ans
        for j in t:
            if j >= int(i):
                ans+=str(j)
                break
        if ans2 == ans:
            ans+='0'
else:
    ans+=str(t[1]) +'0'*len(N)
if int(ans) >= int(N):
    print(ans)
else:
    print(ans+'0')

Submission status: Wrong Answer

Solution code:
N, K = map(str,input().split(' '))
D = set(map(str,input().split(' ')))
ans = ''
t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - D)))
t.append(0)
t.sort()
if N[0] in t:
    ans += N[0]
else:
    ans+=str(t[1])
for i in N[1::]:
    ans2 = ans
    for j in t:
        if j >= int(i):
            ans+=str(j)
            break
    if ans2 == ans:
        ans+='0'
if int(ans) >= int(N):
    print(ans)
else:
    print(ans+'0')

Submission status: Wrong Answer

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

D = set(map(str,input().split(' ')))

n=set(map(str,D))

ans = ''

t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - n)))
t.sort()
t.append(0)

for i in N:
    for j in t:
        if j >= int(i):
            ans+=str(j)
            break
if len(ans) == len(N):
    print(ans)
else:
    print(str(t[0])+'0'*(len(N)))

Submission status: Wrong Answer

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

D = set(map(str,input().split(' ')))

n=set(map(str,D))

ans = ''

t = list(map(int,list({'1','2','3','4','5','6','7','8','9'} - n)))
t.append(0)
t.sort()

for i in N:
    for j in t:
        if j >= int(i):
            ans+=str(j)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding : utf-8 -*-

n, k = map(int, input().split())
D = input().split()
D = list(map(int, D))
E = [0,1,2,3,4,5,6,7,8,9]
for i in range(len(D)):
  E.remove(D[i])
  
for i in range(n, 10 * n+1):
  a = i //1000
  m = i - a*1000
  b = m //100
  l = m - b*100
  c = l // 10
  d = l - c*10
  if a in E and b in E and c in E and d in E:
    print (i)

Submission status: Wrong Answer

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

candidate_num=list(set(['0','1','2','3','4','5','6','7','8','9'])-d)
candidate_num.sort()

from itertools import product
candidate=list(product(candidate_num, repeat=len(str(n))))

ans=10**9+7
for candidate_i in candidate:
    c_i=int(''.join(list(candidate_i)))
    if n<=c_i:
        ans=min(ans,c_i)
print(ans)

Submission status: Wrong Answer

Solution code:
def ret_num(num, val):
  for i in num:
    if i > val:
      return i

all_num=[0,1,2,3,4,5,6,7,8,9]
(val, dis)=[int(x) for x in input().split()]
dis_num=[int(x) for x in input().split()]
num=[]
for i in all_num:
  if i not in dis_num:
    num.append(i)
ans=[]
while val > 0:
  if val % 10 in num:
    ans.append(val%10)
    val=val//10
  elif val % 10 != 9:
    ans.append(ret_num(num, val%10))
    val=val//10
  else:
    ans.append(num[0])
    val=val//10+1
ans.reverse()
for i in ans:
  print(i, end='')
print()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
n=str(n)
cand=[]
flag=True
for i in range(10):
    if not i in lis:
        cand.append(i)
mx=""
for i in range(len(n)):
    mx+=str(cand[-1])
if int(n)>int(mx):
    flag=False
stri=""
if flag==False:
    if 0 in cand:
        v=str(cand[1])
    else:
        v=str(cand[0])
    for i in range(len(n)+1):
        stri+=v
    print(stri)
else:
    for i in range(int(n),10000):
        y=str(i)
        cou=0
        for j in range(len(y)):
            if int(y[j]) in cand:
                cou+=1
        #print(cou)
        if cou==len(y):
            print(y)
            sys.exit()

Submission status: Wrong Answer

Solution code:
class A:

    def solve(self):
        [a, b, c] = sorted([int(x) for x in input().split(" ")])
        if a == 5 and b == 5 and c == 7:
            print("YES")
        else:
            print("NO")

class B:

    def solve(self):
        [n, l] = [int(x) for x in input().split(" ")]

        strings = []
        for r in range(n):
            strings.append(input())

        sorted_strings = sorted(strings)

        print("".join(sorted_strings))

class C:

    def fix(self, final_amount, likes):
        i = 0
        import bisect as b
        changed = False
        for i,x in enumerate(reversed(final_amount)):
            real_index = len(final_amount) - i - 1
            ind = b.bisect_right(likes, int(x))
            if ind != len(likes):
                final_amount[real_index] = str(likes[ind])
                changed = True
                break

        if not changed:
            ind = b.bisect_right(likes, 0)
            final_amount = [str(likes[ind])] + final_amount
            i = 1
        else:
            i = len(final_amount) - i - 1

        while i < len(final_amount):
            final_amount[i] = str(likes[0])
            i += 1

        return final_amount

    def solve(self):
        [n, k] = [int(x) for x in input().split(" ")]
        dislikes = [int(x) for x in input().split(" ")]

        likes = []
        for r in range(10):
            if r not in dislikes:
                likes.append(r)

        import bisect as b

        final_amount = []
        sn = str(n)
        for ind in range(len(sn)):
            c = sn[ind]
            i = b.bisect_left(likes, int(c))
            if i == len(likes):
                prev_len = len(final_amount)
                final_amount = self.fix(final_amount, likes)
                final_amount += [str(likes[0]) for r in range(len(sn) - prev_len)]
                break

            if str(c) != str(likes[i]):
                final_amount.append(str(likes[i]))
                final_amount += [str(likes[0]) for r in range(len(sn) - len(final_amount))]

            final_amount.append(str(likes[i]))

        print("".join(final_amount))

C().solve()

Submission status: Wrong Answer

Solution code:
from itertools import *
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))
ans = 10**18
for i in product(num,repeat=len(str(N))):
  money = int(''.join(list(i)))
  if N <= money :
    ans = min(ans,money)
print(ans)

Submission status: Wrong Answer

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

values = available.copy()
idx = int(values[0] == 0)

while True:
  base = values[idx] * 10
  for a in available:
    n = base + a
    if n >= N:
      print(n)
      quit()
    values.append(n)
  idx += 1

Submission status: Wrong Answer

Solution code:
from itertools import product
n, k = input().split()
a = list(input().split())
l = set([str(i) for i in range(10)]).difference(a)
ni = int(n)
for j in range(len(n), len(n)+2):
    for i in product(l, repeat=j):
        t = ''.join(i)
        if int(t) >= ni:
            print(t)
            exit()

Submission status: Wrong Answer

Solution code:
from collections import deque
n,k = map(int,input().split())
d = set(list(map(int,input().split())))
a = list({0,1,2,3,4,5,6,7,8,9} - d)
a.sort()
que = deque()
que.append(0)

while que:
    ans = que.popleft()
    if ans >= n:
        print(ans)
        exit()
    for i in a:
        que.append(ans*10 + i)
        print(ans*10 + i)

Submission status: Wrong Answer

Solution code:
[n,k] = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ls = []
iter = 0
for i in range(10):
    try:
        if i != d[iter]:
            ls.append(str(i))
        else:
            iter += 1
    except:
        ls.append(str(i))
        pass
#print(ls)
ans = 10 ** 5
for i in range(len(ls)):
    for j in range(len(ls)):
        for k in range(len(ls)):
            for l in range(len(ls)):
                tmp = int(ls[i] + ls[j] + ls[k] + ls[l])
                #print(tmp)
                if tmp >= n and ans > tmp:
                    ans = tmp
print(ans)

Submission status: Wrong Answer

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

canidates = [i for i in range(10) if i not in d]
ok = False
ans = 10**9
def bfs(s):
    global ans
    if len(s) == len(str(n)):
        res = int(s)
        if res >= n and res < ans:
            ans = res
    else:
        for i in canidates:
            bfs(s+str(i))
bfs('')
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
ds=list(map(str, input().split()))
while True:
  for i in ds:
    if i in str(n):
      n+=1
      break
  break
print(str(n))

Submission status: Wrong Answer

Solution code:
n,k=map(int, input().split())
ds=list(map(str, input().split()))
while True:
  for i in ds:
    if i in str(n):
      n+=1
      continue
  break
print(str(n))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = input().split()
i = 0
while i < 1:
  i = 1
  for n in str(N):
    if n in D:
      i = 0
  N += 1
print(N)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = input().split()
n = 1
i = 0
while i < 1:
  Ans = str(N * n)
  n += 1
  i = 1
  for ans in Ans:
    if ans in D:
      i = 0
print(Ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？



n,k=mii()
p=limii()
q=[0,1,2,3,4,5,6,7,8,9]
arr=[]
for i in q:
    if i not in p:
        arr.append(i)
ans=10**100
for i in range(len(list(str(n))),5):
    for mat in list(product(arr, repeat=i)):
        if int("".join([str(l) for l in mat]))>=n:
            ans=min(ans,int("".join([str(l) for l in mat])))
            
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？



n,k=mii()
p=limii()
q=[0,1,2,3,4,5,6,7,8,9]
arr=[]
for i in q:
    if i not in p:
        arr.append(i)
ans=10**100
for i in range(len(list(str(n))),5):
    for mat in list(product(arr, repeat=i)):
        if int("".join([str(l) for l in mat]))>=n:
            ans=min(ans,int("".join([str(l) for l in mat])))
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n , k = map(int,input().split())
d = set(list(map(int,input().split())))
kouho =list({0,1,2,3,4,5,6,7,8,9} - d)
kouho.sort()

def f(now):
    if now >= n:
        print(now)
        exit()
    for i in kouho:
        if now != 0 or i != 0:
            f(now*10 + i)

f(0)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
like = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
ans = ''
result_list = list(set(like) - set(d))
result_list.sort()
for i in str(n):
    for result in result_list:
        if int(i) == result == 0:
            ans = ans + '0'
            break
        elif int(i) <= result:
            ans = ans + str(result)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
like = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
ans = ''
result_list = list(set(like) - set(d))
for i in str(n):
    for result in result_list:
        if int(i) == result == 0:
            ans = ans + '0'
        elif int(i) <= result:
            ans = ans + str(result)
print(ans)

Submission status: Wrong Answer

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

N = l[0]
K = l[1]

s = list(map(int, input().split()))
number = [0,1,2,3,4,5,6,7,8,9]
not_in = []

for i in range(10):
  if i not in s:
    not_in.append(i)
    
result = ""
flg = 0

upper = str(N)[0]

for j in not_in:
  if int(upper) <= j:
    flg = 1
if flg == 0:
  N = "10" + str(N)[1:]
    
for index,i in enumerate(str(N)):
  for j in not_in:
    if int(i) <= j:
      result += str(j)      
      break
print(result)

Submission status: Wrong Answer

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

N = l[0]
K = l[1]

s = list(map(int, input().split()))
number = [0,1,2,3,4,5,6,7,8,9]
not_in = []

for i in range(10):
  if i not in s:
    not_in.append(i)
    
result = ""
for i in str(N):
  for j in not_in:
    if int(i) <= j:
      result += str(j)
      break
print(result)

Submission status: Wrong Answer

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

#嫌いな数字を変更する
def change_number(x):
  
  #足す数を格納しておく変数
  tmp = 0

  #嫌いな数字が含まれている間
  while x in d:
    x += 1
    tmp += 1
    #繰り上がる場合に調整
    if x == 10:
      x = 0
  
  return tmp

#1の位
x = str(n)[-1:]
n += change_number(int(x))

#10の位
if n >= 10:
  x = str(n)[-2:-1]
  n += change_number(int(x)) * 10

#100の位
if n >= 100:
  x = str(n)[-3:-2]
  n += change_number(int(x)) * 100

#1000の位
if n >= 1000:
  x = str(n)[-4:-3]
  n += change_number(int(x)) * 1000
  
#10000の位
if n >= 10000:
  x = str(n)[-5:-4]
  n += change_number(int(x)) * 10000

print(n)

Submission status: Wrong Answer

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

#嫌いな数字を変更する
def change_number(x):
  
  #足す数を格納しておく変数
  tmp = 0

  #嫌いな数字が含まれている間
  while x in d:
    x += 1
    tmp += 1
    #繰り上がる場合に調整
    if x == 10:
      x = 0
  
  return tmp

#1の位
x = str(n)[-1:]
n += change_number(int(x))

#10の位
if n >= 10:
  x = str(n)[-2:-1]
  n += change_number(int(x)) * 10

#100の位
if n >= 100:
  x = str(n)[-3:-2]
  n += change_number(int(x)) * 100

#1000の位
if n >= 1000:
  x = str(n)[-4:-3]
  n += change_number(int(x)) * 1000

print(n)

Submission status: Wrong Answer

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

#嫌いな数字を変更する
def change_number(x):
  
  #足す数を格納しておく変数
  tmp = 0

  #嫌いな数字が含まれている間
  while x in d:
    x += 1
    tmp += 1
    #繰り上がる場合に調整
    if x == 10:
      x = 0
  
  return tmp

#1の位
x = str(n)[-1:]
n += change_number(int(x))

#10の位
if n >= 10:
  x = str(n)[-2:-1]
  n += change_number(int(x)) * 10

#100の位
if n >= 100:
  x = str(n)[-3:-2]
  n += change_number(int(x)) * 100

#1000の位
if n >= 1000:
  x = str(n)[-4:-3]
  n += change_number(int(x)) * 1000

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
number=[i for i in range(10) if i not in D]
#N以上の最小値をnumberの数値だけで表せ
#0が許されるなら、末端は
#K*5*

for i in range(N,10001):
    c=0
    for j in str(i):
        if int(j) not in number:
            c=1
            break
    if c==0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

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

tmp =[]
for i in list(n):
    ni = int(i)
    while True:
        if ni in d:
            ni += 1
        else:
            tmp.append(ni)
            break

print("".join(list(map(str,tmp))))

Submission status: Wrong Answer

Solution code:
# C - こだわり者いろはちゃん
# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 入力 1
# 1000 8
# 1 3 4 5 6 7 8 9

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

# Nの各桁をみて、嫌いな数字が入っていないかチェック
# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
# これを嫌いな数字がなくなるまで繰り返す。

nums = list(N) # 各桁

i = 1

# 嫌いな数字が入っていたら、その桁をインクリメントして、整数(N)を再生性する。
while i != 0:
    tmp = []
    j = 0
    for num in nums :
        if num in D:
            tmp.append(str(int(num) + 1))
            j = 1
        else :
            tmp.append(num)
    
    # 嫌いな数字があったか判定
    if j == 1:
        i = 1
        nums = "".join(tmp)
    else :
        print("".join(tmp))
        exit()

# テストケース

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().rstrip().split())
dislikes = list(map(int,input().rstrip().split()))
n = str(n)
len_n = len(n)
separate_n = [int(s) for s in n]

pay = separate_n.copy()
up_nextlevel = False
for i in range(len(separate_n)-1,-1,-1):
    up_nextlevel = False
    if separate_n[i] in dislikes:
        for j in range(10):
            num = separate_n[i]+j
            if num > 9:
                num -= 10
                up_nextlevel = True
            if not(num in dislikes):
                pay[i] = num
                break
    else:
        continue
if up_nextlevel:
    for i in range(1,10):
        if not(i in dislikes):
            print(i,end="")
            break
for p in pay:
    print(p,end="")

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().rstrip().split())
dislikes = list(map(int,input().rstrip().split()))
n = str(n)
len_n = len(n)
separate_n = [int(s) for s in n]

pay = separate_n.copy()
up_nextlevel = False
for i in range(len(separate_n)-1,-1,-1):
    up_nextlevel = False
    if separate_n[i] in dislikes:
        for j in range(10):
            num = separate_n[i]+j
            if num > 9:
                num -= 10
                up_nextlevel = True
            if not(num in dislikes):
                pay[i] = num
                break
    else:
        continue
if up_nextlevel:
    print('1',end="")
for p in pay:
    print(p,end="")

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [int(d) for d in input().split()]
n_len = len(str(n))

def rec_define_digit(i, s):
    ans = 100000
    if i == n_len:
        val = int(s)
        if val >= n:
            return val
        else:
            return ans
    else:
        for x in range(10):
            if x not in d:
                ans = min(ans, rec_define_digit(i + 1, s + str(x)))
        return ans

print(rec_define_digit(0, ""))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

nums = list(range(10))

for num in hate:
    if num in nums:
        nums.remove(num) 


def make_numbers(x):
    out = ""
    x_dumy = x
    while x_dumy >0:
        out = str(nums[x_dumy%len(nums)]) + out
        x_dumy = int(x_dumy/len(nums))

    return int(out)

ans = 1
for i in range(n+1):
    if i > make_numbers(ans):
        ans += 1

print(make_numbers(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

nums = list(range(10))

for num in hate:
    if num in nums:
        nums.remove(num) 


def make_numbers(x):
    out = ""
    x_dumy = x
    while x_dumy >0:
        out = str(nums[x_dumy%len(nums)]) + out
        x_dumy = int(x_dumy/len(nums))

    return int(out)

ng = 0
ok = 10 ** 4

while ok - ng > 1:
    mid = (ok + ng) // 2
    if make_numbers(mid) < n:
        ng = mid
    else:
        ok = mid

print(make_numbers(mid))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(500000)

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

ans = []
def dfs(p:str):
    if int(p)>=n:
        ans.append(int(p))
        return

    if len(p)>len(str(n))+1:
        return

    for i in range(1,10):
        if not i in D:
            dfs(p+str(i))

for i in range(10):
    if not i in D:
        dfs(str(i))

print (min(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    D=set(input().split())
    for i in range(1,10**7):
        p=N*i
        if not set(str(p))&D:
            print(p)
            exit()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = {0,1,2,3,4,5,6,7,8,9}-set(a) #使用可能な数字の集合
print(set([int(i) for i in list(str(n))])-b)
while set([int(i) for i in list(str(n))])-b !=set() : # 使用可能な数字のみでなければ
    n += 1
print(n)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
n2 = [int(i) for i in list(str(n))] #価格を分解
for i in range(len(n2)):
    while n2[i] in a :#使用不可ならば
        n2[i] += 1
        if n2[i]>=10:
            n2[i] =1

print("".join([str(i) for i in n2]))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
print(a)
n2 = [int(i) for i in list(str(n))] #価格を分解
for i in range(len(n2)):
    while n2[i] in a :#使用不可ならば
        n2[i] += 1
        if n2[i]>=10:
            n2[i] =1

print("".join([str(i) for i in n2]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
lis = []
for i in range(10):
    if not i in d:
        lis.append(i)
inf = 1001001001
ans = inf
def dfs(s, n):
    if len(s) >= len(str(n)) + 2:
        if int(s) >= n:
            global ans
            ans = min(ans, int(s))
        return
    else:
        for i in lis:
            dfs(s + str(i), n)
dfs("", n)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
lis = []
for i in range(10):
    if not i in d:
        lis.append(i)
inf = 1001001001
ans = inf
def dfs(s, n):
    if len(s) >= len(str(n)) + 1:
        if int(s) >= n:
            global ans
            ans = min(ans, int(s))
        return
    else:
        for i in lis:
            dfs(s + str(i), n)
dfs("", n)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
lis = []
for i in range(10):
    if not i in d:
        lis.append(i)
inf = 1001001001
ans = inf
def dfs(s, n):
    if len(s) == 4:
        if int(s) >= n:
            global ans
            ans = min(ans, int(s))
        return
    else:
        for i in lis:
            dfs(s + str(i), n)
dfs("", n)
print(ans)

Submission status: Wrong Answer

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

ok = [i for i in range(k) if i not in d]

check = 1
for x in str(n):
   if int(x) in d:
      check = 0
      break
if check == 1:
   print(n)
   exit()

ans = [int(x) for x in str(n)]
while (1):
   ans[-1] += 1
   for i in reversed(range(0, len(ans))):
      if ans[i] >= 10:
         if i == 0:
            ans.insert(0, 1)
         else:
            ans[i-1] += 1
         ans[i] -= 10

   diff = set(ans) & set(d)
   if len(diff) == 0:
      break

print(''.join([str(x) for x in ans]))