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())
hate_list=map(int,input().split())

p_list=[]
ok_list=[]

s=0
for x in hate_list:
    while x>s:
        ok_list.append(s)
        s+=1
    s+=1
ok_list.append(10)

# nの桁をリスト化
ndgts=[]
while n>0:
    ndgts.append(n%10)
    n//=10

flag=0 #necessality of a comparison
for y in reversed(ndgts):
    if flag>0:
        p_list.append(0)
        continue
    for x in range(11-k):
        if y==ok_list[x]:
            p_list.append(x)
            break
        elif y< ok_list[x]:
            p_list.append(x)
            flag=1
            break


print(p_list)
p_list.reverse()
for x in range(len(p_list)-1):
    if p_list[x]==10-k:
        p_list[x]=0
        p_list[x+1]+=1

if p_list[-1]==10-k:
    p_list[-1]=0
    if ok_list[0]==0:
        p_list.append(1)
    else:
        p_list.append(0)
payment=0
print(p_list)
for x in reversed(p_list):
    payment=10*payment + ok_list[x]
print(payment)

Submission status: Wrong Answer

Solution code:

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

payment_list=[]
ok_list=[]
s=0
for x in hate_list:
    while x>s:
        ok_list.append(s)
        s+=1
    s+=1

ok_list.append(10)
ndgts=[]
while n>0:
    ndgts.append(n%10)
    n//=10
# print(ndgts)
flag=True
for y in reversed(ndgts):
    if flag == False:
        payment_list.append(10-k)
        continue
    for x in range(len(ok_list)):
        if y<=ok_list[x]:
            payment_list.append(x)
            if x==10-k:
                flag=False
            break

payment_list.reverse()
for x in range(len(payment_list)-1):
    if payment_list[x]==10-k:
        payment_list[x]=0
        if payment_list[x+1]<10-k:
            payment_list[x+1]+=1
if payment_list[-1]==10-k:
    payment_list[-1]=0
    if ok_list[0]==0:
        payment_list.append(1)
    else:
        payment_list.append(0)
payment=0
# print(payment_list)
for x in reversed(payment_list):
    payment=10*payment + ok_list[x]
print(payment)

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    D = list(map(int,input().split()))

    num = [x for x in range(10) if x not in D]
    ans = []
    while n > 0:
        x = n%10
        n //= 10
        flag = True
        for i in range(len(num)):
            if x <= num[i]:
                flag = False
                ans.append(num[i])
                break
        
        if flag:
            ans.append(num[0])
    
    print("".join(map(str,ans[::-1])))
main()

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    D = list(map(int,input().split()))

    num = [x for x in range(10) if x not in D]
    ans = []
    while n > 0:
        x = n%10
        n //= 10
        flag = True
        for i in range(len(num)):
            if x <= num[i]:
                flag = False
                ans.append(num[i])
                break
        
        if flag:
            ans.append(num[0])
    
    print("".join(map(str,ans[::-1])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,math,itertools
input = sys.stdin.readline
n, k = map(int, input().split())
d = [int(_) for _ in input().split()]
d_set = set(d)
d_all = set(range(10))
d_use = [str(a) for a in list(d_all - d_set)]
keta = int(math.log10(n))+1
l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 10000 for a in list(itertools.product(d_use, repeat=keta+1))]
l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 10000 for a in list(itertools.product(d_use, repeat=keta))]

print(min(min(l1), min(l2)))

Submission status: Wrong Answer

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

for price in range(n, 10001):
    if len(set(list(str(price))) - D) == len(set(list(str(price)))):
        print(price)
        break

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = [int(i) for i in input().split()]
nl = list(str(n))
N = map(int,nl)
r = []
for i in N:
	for j in l:
		if i == j:
			i = i+1
		else:
			r.append(i)
			break
r1 = map(str,r)
print("".join(r1))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
dp=[0]*10
for i in range(K):
  dp[D[i]]=1
for i in range(N,10**6+1):
  a=str(i)
  flag=True
  for j in range(len(a)):
    if dp[int(a[j])]==1:
      flag=False
      break
    if flag:
      print(i)
      exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
dp=[0]*10
for i in range(K):
  dp[D[i]]=1
for i in range(N,10**5+1):
  a=str(i)
  flag=True
  for j in range(len(a)):
    if dp[int(a[j])]==1:
      flag=False
      break
    if flag:
      print(i)
      exit()

Submission status: Wrong Answer

Solution code:
import math
N, K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10)]

for i in l:
    num.remove(i)
# print(num)

keta = int(math.log10(N))
digit = int(10**keta)
ans = 0

if num[0] == 0:
    ans += digit * num[1]
    digit /= 10
    for i in range(keta):
        ans += digit * num[0]
        digit /= 10

if num[0] != 0:
    ans += digit * num[0]
    digit /= 10
    for i in range(keta):
        ans += digit * num[0]
        digit /= 10

print(int(ans))

Submission status: Wrong Answer

Solution code:
n,k,*a=map(int,open(0).read().split())
for i in range(n,10**6):
    if not set(str(i))&set(a):
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = [int(i) for i in input().split()]
l = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
for i in range(K):
    l.remove(D[i])
n = [int(x) for x in str(N)]
c = len(n)

l_max = l[0]
l_min = l[-1]
p = 0
q = 0
r = 1
for _ in range(c):
    p += r * l_max
    q += r * l_min
    r *= 10
if N > p:
    b = r*min([i for i in l if i>0]) + q
else:
    a = [l_max] * c
    for j in range(c):
        if a[j] > n[j]:
            a[j] = min([i for i in l if i>=n[j]])
    b = ""
    for j in range(c):
        b += str(a[j])
    b = int(b)

print(b)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = [int(i) for i in input().split()]
l = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
for i in range(K):
    l.remove(D[i])
n = [int(x) for x in str(N)]
c = len(n)

l_max = l[0]
l_min = l[-1]
if N > 1111 * l_max:
    b = 10000*min([i for i in l if i>0]) + 1111*l_min
else:
    a = [l_max] * c
    for j in range(c):
        if a[j] > n[j]:
            a[j] = min([i for i in l if i>=n[j]])
    b = ""
    for j in range(c):
        b += str(a[j])
    b = int(b)

print(b)

Submission status: Wrong Answer

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

use_num = []
for i in range(10):
    if i in d:continue
    use_num.append(i)

str_n = str(n)
res = 0
for i in str_n:
    temp = bisect_left(use_num, int(i))
    
    if temp == len(use_num):
        add = use_num[0] * 10
    else:
        add = use_num[temp]
    res = res * 10 + add 
print(res)

Submission status: Wrong Answer

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

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

for i, ni in enumerate(l):
    for j, nj in enumerate(a):
        if ni <= nj:
            l[i] = nj
            break

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
allowed = list(range(10))
for d in D:
    allowed.remove(d)

# L = list(map(int,list(str(N))[::-1]))
b = 0
# for n in L:
lenN = len(str(N))
while b < lenN:
    base = 10**b
    target = N//base%10
    if target not in allowed:
        next = target + 1
        while not next in allowed and next < 10:
            next += 1
        N -= target*base
        if next < 10 :
            N += next*base
        else:
            N += allowed[0]*base
            N += base*10
            
    b += 1

print(N)

Submission status: Wrong Answer

Solution code:
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList:
        if n[i] < y:
            n[i] = y
            j = i+1
            while j < len(n):
                print(n[j])
                n[j] = okList[0]
                j += 1

            break
    else:
        if i - 1 < 0:
            n = [0] + n
            i += 1
        n[i - 1] += 1
        j = i
        while j < len(n):
            print(n[j])
            n[j] = okList[0]
            j += 1
print(int("".join(list(map(str, n)))))

Submission status: Wrong Answer

Solution code:
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList:
        if n[i] < y:
            n[i] = y
            break
    else:
        if i - 1 < 0:
            n = [0] + n
            i += 1
        n[i - 1] += 1
        n[i] = okList[0]
print(int("".join(list(map(str, n)))))

Submission status: Wrong Answer

Solution code:
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList[::-1]:
        if n[i] > y:
            if i - 1 < 0:
                n = [0] + n
                i += 1
            n[i - 1] += 1
            n[i] = okList[0]
            break
        elif n[i] < y:
            n[i] = y
            break
print(int("".join(list(map(str, n)))))

Submission status: Wrong Answer

Solution code:
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList[::-1]:
        if n[i] > y:
            if i - 1 < 0:
                n = [0] + n
            n[i - 1] += 1
            break
        elif n[i] < y:
            n[i] = y
            break
print(int("".join(list(map(str, n)))))

Submission status: Wrong Answer

Solution code:
def main():
    n, k = input().split()
    ds = list(map(int, input().split()))
    p_num = list(set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(ds))
    p_num.sort()
    ans = []
    if max(p_num) < int(n[0]):
        if (min(p_num) != 0):
            ans.append(str(p_num[0]))
        else:
            ans.append(str(p_num[1]))

        ans.append(str(min(p_num))*len(n))
        ans = int(''.join(ans))
        return ans

    flag = False
    for i, s in enumerate(n):
        for p in p_num:
            if len(ans) != 0 and int(s) < p:
                flag = True
                ans.append(str(p))
                ans.append(len(n[i:])*str(min(p_num)))
                break
            if int(s) <= p:
                ans.append(str(p))
                break

        if flag:
            break

    return int("".join(ans))


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = input().split()
    ds = list(map(int, input().split()))
    p_num = list(set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(ds))
    p_num.sort()
    ans = []
    if max(p_num) < int(n[0]):
        if (min(p_num) != 0):
            ans.append(str(p_num[0]))
        else:
            ans.append(str(p_num[1]))

        ans.append(str(min(p_num))*len(n))
        ans = int(''.join(ans))
        return ans

    flag = False
    for i, s in enumerate(n):
        for p in p_num:
            if len(ans) != 0 and int(s) < p:
                flag = True
                ans.append(str(p))
                ans.append(len(n[i:])*str(min(p_num)))

            if int(s) <= p:
                ans.append(str(p))
                break

        if flag:
            break

    return int("".join(ans))


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = input().split()
    ds = list(map(int, input().split()))
    p_num = list(set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(ds))
    p_num.sort()
    ans = []
    if max(p_num) < int(n[0]):
        if (min(p_num) != 0):
            ans.append(str(p_num[0]))
        else:
            ans.append(str(p_num[1]))

        ans.append(str(min(p_num))*len(n))
        ans = int(''.join(ans))
        return ans

    for s in n:
        for p in p_num:
            if int(s) <= p:
                ans.append(str(p))
                break

    return int("".join(ans))


if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

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

dislike = set(list(map(int, input().split())))

next_map = {}
min_digit = 0
for i in range(10):
    for j in range(i,10):
        if j not in dislike:
            if i == 0:
                min_digit = j
            next_map.update({ i : j })
            break
        next_map.update({ i : min_digit })
max_digit = max(next_map.values())

num = len(list(N))
count = num
cand = []
for n in list(N):
    n = int(n)
    if n in dislike:
        n_ = next_map[n]
        cand.append(n_)
        count -= 1
        cand.extend(count*[min_digit])
        break
    else:
        cand.append(n)
        count -= 1
print(cand)
cand = int("".join(list(map(str, cand))))
if int(N) <= cand:
    print(cand)
else:
    if min_digit == 0:
        next_min = next_map[1]
        cand = [next_min] + num * [0]
    else:
        cand = (num + 1) * [min_digit]
    cand = int("".join(list(map(str, cand))))
    print(cand)

Submission status: Wrong Answer

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

dislike = set(list(map(int, input().split())))


next_map = {}
min_digit = 0
for i in range(10):
    for j in range(i,10):
        if j not in dislike:
            if i == 0:
                min_digit = j
            next_map.update({ i : j })
            break
        next_map.update({ i : min_digit })
max_digit = max(next_map.values())

num = len(list(N))

count = num
cand = []
for n in list(N):
    n = int(n)
    if n in dislike:
        n_ = next_map[n]
        cand.append(n_)
        count -= 1
        cand.extend(count*[min_digit])
        break
    else:
        cand.append(n)
cand = int("".join(list(map(str, cand))))
if int(N) <= cand:
    print(cand)
else:
    if min_digit == 0:
        next_min = next_map[1]
        cand = [next_min] + num * [0]
    else:
        cand = (num + 1) * [min_digit]
    cand = int("".join(list(map(str, cand))))
    print(cand)

Submission status: Wrong Answer

Solution code:
D = [i for i in range(10)]
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.reverse()
ans = 100000
for i in A:
    D.pop(i)
p = len(D)
for i in range(p ** 6):
    R = 0
    for i2 in range(7):
        if i >= p ** i2:
            R += D[(i // (p ** i2)) % p] * (10 ** i2)
    if R >= N and R < ans:
        ans = R
print(ans)

Submission status: Wrong Answer

Solution code:
D = [i for i in range(10)]
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.reverse()
ans = 100000
for i in A:
    D.pop(i)
p = len(D)
for i in range(p ** 5 + 1):
    R = 0
    for i2 in range(6):
        if i >= p ** i2:
            R += D[(i // (p ** i2)) % p] * (10 ** i2)
    if R >= N and R < ans:
        ans = R
        break
print(ans)

Submission status: Wrong Answer

Solution code:
D = [i for i in range(10)]
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.reverse()
ans = 100000
for i in A:
    D.pop(i)
p = len(D)
for i in range(p ** 5 + 1):
    R = 0
    for i2 in range(6):
        if i > p ** i2:
            R += D[(i // (p ** i2)) % p] * 10 ** i2
    if R >= N and R < ans:
        ans = R
        break
print(ans)

Submission status: Wrong Answer

Solution code:
D = [i for i in range(10)]
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
A.reverse()
ans = 100000
for i in A:
    D.pop(i)
print(D)
p = len(D)
for i in range(p ** 5 + 1):
    R = 0
    for i2 in range(6):
        if i > p ** i2:
            R += D[(i // (p ** i2)) % p] * 10 ** i2
    if R >= N and R < ans:
        ans = R
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for num in range(n,20001):
    num=str(num)
    ok=True
    for c in num:
        if c in d:
            ok=False
    if ok:
        print(num)
        exit()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
D = set(map(int,input().split()))
notD = [str(i) for i in list(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) ^ D)]
strN = list(str(N))
result = list(str(N))
for i in range(len(strN)):
  if i == 0:
    if strN[i] not in notD:
      for j in notD:
        if j == '0':
          continue
        if int(j) > int(strN[i]):
          result[i] = int(j)
          break
  else:
    if strN[i] not in notD:
      for j in notD:
        if int(j) > int(strN[i]):
          result[i] = int(j)
          break
print(*result,sep='')

Submission status: Wrong Answer

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

d = range(10)
n = set(d) - set(D)

number = set()
for x in str(N):
    number.add(int(x))

if n >= number:
    print(N)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=set([int(x) for x in input().split()])
for i in range(n,10001):
    flag=True
    for j in str(d):
        if j in str(i):
            flag=False
            break
    if flag==True:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=set([int(x) for x in input().split()])
s=set([1,2,3,4,5,6,7,8,9,0])
s=list(s-d)
s.sort()
#print(s)
ans=""
x=str(n)
i=0
while i<len(x):
    for j in s:
        if j>=int(x[i]):
            ans+=str(j)
            break
    i+=1
    

print(ans)

Submission status: Wrong Answer

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

for i in range(n,10001):
  #print(i)
  res = 0
  for j in str(d):
    if j in str(i):
      res += 1
  if res == 0:
    print(i)
    break

Submission status: Wrong Answer

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

for i in range(n,10001):
  #print(i)
  res = 0
  for j in d:
    if j in str(i):
      res += 1
  if res == 0:
    print(i)
    break

Submission status: Wrong Answer

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

for i in range(n,10001):
  res = 0
  for j in d:
    if j in str(i):
      res += 1
  if res == 0:
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
import sys
N, K = map(int, input().split())
d = list(map(int, input().split()))
D = set(d)
N = str(N)
l = len(N)
M = 0
A = False
for i in range(l - 1, -1, -1):
    if A:
        for m in range(10):
            if not m in D:
                M += m * 10 ** i
                break
    else:
        n = int(N[l - i - 1])
        if n in D:
            for m in (n + 1, 10):
                if not m in D:
                    M += m * 10 ** i
                    A = True
                    break
                M += 10 ** (i + 1)
                A = True
        else:
            M += n * 10 ** i

print(M)

Submission status: Wrong Answer

Solution code:
import sys
N, K = map(int, input().split())
d = list(map(int, input().split()))
D = set(d)
N = str(N)
l = len(N)
M = 0
for i in range(l - 1, -1, -1):
    n = int(N[l - i - 1])
    if n in D:
        a = True
        for m in (n + 1, 10):
            if not m in D:
                M += m * 10 ** i
                a = False
                break
        if a:
            M += 10 ** (i + 1)
    else:
        M += n * 10 ** i

print(M)

Submission status: Wrong Answer

Solution code:
import sys
N, K = map(int, input().split())
d = list(map(int, input().split()))
D = set(d)
N = str(N)
l = len(N)
M = 0
for i in range(l - 1, -1, -1):
    n = int(N[l - i - 1])
    if n in D:
        for m in (n + 1, 10):
            if not m in D:
                M += m * 10 ** i
                print(M)
                sys.exit()
        M += 10 ** (i + 1)
        break
    else:
        M += n * 10 ** i

print(M)

Submission status: Wrong Answer

Solution code:
import sys
N, K = map(int, input().split())
d = list(map(int, input().split()))
D = set(d)
N = str(N)
l = len(N)
M = 0
for i in range(l - 1, -1, -1):
    n = int(N[l - i - 1])
    if n == 0:
        continue
    if n in D:
        for m in (n + 1, 10):
            if not m in D:
                M += m * 10 ** i
                print(M)
                sys.exit()
        M += 10 ** (i + 1)
        break
    else:
        M += n * 10 ** i

print(M)

Submission status: Wrong Answer

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)
#print(a)

from collections import deque

q=deque()
q.extend(a)

while True:
    qq=q.popleft()
    #print(q)
    for item in a:
        qqq=qq+item
        #print(qqq[::-1])
        if int(qqq[::-1])>=n:
            print(qqq[::-1])
            sys.exit()
        q.append(qqq[::-1])

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
Dislike = list(map(int,input().split()))
Like = []
for i in range(10):
    if i not in Dislike:
        Like.append(i)
D = []
while(N):
    D.append(N%10)
    N //=10
nod = len(D)
for i in range(nod//2):
    temp = D[i]
    D[i] = D[nod-i-1]
    D[nod-i-1] = temp
ND=[]
for i in D:
    if i not in Like:
      lo = 0
      hi = len(Like)-1
      while(lo<hi):
        mid = lo + ((hi-lo)//2)
        if i<Like[mid]:
            hi = mid 
        else:
            lo = mid+1
      ND.append(Like[lo])
    else:
      ND.append(i)
for i in ND:
  print(i,end="",sep="")

Submission status: Wrong Answer

Solution code:
import sys
n,k=map(int,input().split())
d=list(map(int,input().split()))
allowed=set()
for i in range(10):
  allowed.add(i)
for i in d:
  allowed.remove(i)
for i in range(n,10**7):
  b=str(i)
  c=set()
  for j in range(len(b)):
    c.add(b[j])
  if allowed.intersection(c)==set():
    print(i)
    sys.exit()

Submission status: Wrong Answer

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

bn = sorted(list((set([0,1,2,3,4,5,6,7,8,9]) - D_list)))

res = 0
for i0 in bn:
    v0 = i0 * 100000
    for i1 in bn:
        v1 = i1 * 1000
        for i2 in bn:
            v2 = i2 * 100
            for i3 in bn:
                v3 = i3 * 10
                for v4 in bn:
                    money = v0+v1+v2+v3+v4
                    if money >= N:
                        print(money)
                        exit()

Submission status: Wrong Answer

Solution code:
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin = open("input.txt","r")  # <<<  Comment this line  >>> #
    sys.stdout = open("output.txt","w")  # <<<  Comment this line  >>> #
    sys.stderr = open("output.txt","w")  # <<<  Comment this line  >>> #

# for _testcases_ in range(int(input())):
n, r = get_ints()
se = set(range(9))
li = set(get_list())
se = se.difference(li)
se = set(map(str, se))
while True:
    flag = True
    for i in str(n):
        if i not in se:
            flag = False
            break
    if flag:
        print(n)
        break
    n += 1



'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Submission status: Wrong Answer

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

def answer(N,d):
    ans = N
    while True:
        sra = str(ans)
        for i in range(len(sra)):
            if sra[i] in d:
                ans = int(sra) + 1
                break
            return sra

print(answer(N,d))

Submission status: Wrong Answer

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

import sys

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

for i in range(1, 100):
    total = n * i
    st = set(int(x) for x in str(total))
    l = len(st)
    if len([x for x in st if x not in D]) == l:
        print(total)
        break

Submission status: Wrong Answer

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

import sys

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

try:
	sl = input()
except EOFError:
	print(n)
	sys.exit(0)
    
ds = set(map(int, sl.split()))

for i in range(1, 100):
    total = n * i
    st = set(int(x) for x in str(total))
    l = len(st)
    if len([x for x in st if x not in ds]) == l:
        print(total)
        break

Submission status: Wrong Answer

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

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

ds = set(map(int, input().split()))

for i in range(1, 100):
    total = n * i
    st = set(int(x) for x in str(total))
    l = len(st)
    if len([x for x in st if x not in ds]) == l:
        print(total)
        break

Submission status: Wrong Answer

Solution code:
n,k=input().split()
d=set(range(10))-set(map(int,input().split()))
p=0
l=[0]*10
for i in range(10):
    if i in d:
        l[p:i+1]=[i for j in range(i-p+1)]
        p=i+1
if p!=10:
    d.discard(0)
    i=min(d)*10
    l[p:]=[i for j in range(10-p)]
#print(l)
p=0
t=len(n)
for i in range(t):
    p+=10**(t-i-1)*l[int(n[i])]
    if l[int(n[i])]!=int(n[i]):
        break
print(p)

Submission status: Wrong Answer

Solution code:
n,k=input().split()
d=set(range(10))-set(map(int,input().split()))
p=0
l=[0]*10
for i in range(10):
    if i in d:
        l[p:i+1]=[i for j in range(i-p+1)]
        p=i+1
if p!=10:
    d.discard(0)
    i=min(d)*10
    l[p:]=[i for j in range(10-p)]
print(l)
p=0
t=len(n)
for i in range(t):
    p+=10**(t-i-1)*l[int(n[i])]
    if l[int(n[i])]!=int(n[i]):
        break
print(p)

Submission status: Wrong Answer

Solution code:
n,k=input().split()
d=set(range(10))-set(map(int,input().split()))
p=0
l=[0]*10
for i in range(10):
    if i in d:
        l[p:i+1]=[i for j in range(i-p+1)]
        p=i+1
if p!=10:
    d.discard(0)
    i=min(d)*10
    l[p:]=[i for j in range(10-p)]
#print(l)
p=0
t=len(n)
for i in range(t):
    p+=10**(t-i-1)*l[int(n[i])]
print(p)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = list(map(str, input().split()))
for i in range(n, 10000):
    num = str(i)
    for j in range(len(num)):
        if num[j] in d:
            break
    else:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from collections import Counter


def ok(n, D):
    # Dに含まれる数字をnで使っていたらFalse
    counter = Counter(str(n))
    for d in D:
        if counter[str(d)] > 0:
            return False
    return True


def main():
    N, K = list(map(int, input().split(' ')))
    D = list(map(int, input().split(' ')))
    print(ok(1334, [0, 1, 2, 4]))
    while not ok(N, D):
        N += 1
    print(N)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n, 10000):
    flag = True
    for j in list(str(i)):
        if j in d:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Wrong Answer

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

keta = int(len(str(n)))
ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

ans = ''
for i in reversed(range(keta)):
    val = int(str(n)[i])
    candidate = [j for j in ok if j >= val]
    if candidate:
        ans += str(min(candidate))
    else:
        ans = str(min(ok))

ans = ''.join(reversed(list(ans)))
if int(ans) < n:
    idx = ok.index(int(ans[0]))
    if idx == len(ok) - 1:
        ans = str(min(ok)) * (keta + 1)
    else:
        ans = str(ok[idx + 1]) + str(min(ok)) * (keta - 1)

print(ans)

Submission status: Wrong Answer

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

keta = int(len(str(n)))
ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

ans = ''
for i in reversed(range(keta)):
    val = int(str(n)[i])
    candidate = [j for j in ok if j >= val]
    if candidate:
        ans += str(min(candidate))
    else:
        ans = str(min(ok))

ans = ''.join(reversed(list(ans)))
if int(ans) < n:
    ans = str(min(ok)) * (keta + 1)
print(ans)

Submission status: Wrong Answer

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

keta = int(len(str(n)))
ok = sorted(list(set(d) ^ {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}))

ans = ''
for i in reversed(range(keta)):
    val = int(str(n)[i])
    candidate = [j for j in ok if j >= val]
    if candidate:
        ans += str(min(candidate))
    else:
        ans = str(min(ok))

ans = ''.join(reversed(list(ans)))
if int(ans) < n:
    ans = str(min(ok)) + ans

print(ans)