Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
if k == 0 or 9:
    print(n)
    exit(0)
for ans in range(n,10000):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
from itertools import count
for ans in count(n,1):
    for c in str(ans):
        if int(c) in D:
            print(ans)
            break
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
D = set(map(int, input().split()))
for ans in range(n,10000):
    for c in str(ans):
        if int(c) in D:
            break
    else:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n,k = input().split()
hate = list(input().split())
exi = False

while True:
    for c in hate:
        if c in list(n):
            break
        else:
            exi = True
            break
    if exi:
        break
    intN = int(n) + 1
    n = str(intN)
    
print(n)

Submission status: Wrong Answer

Solution code:
m,n = list(map(int,input().split(" ")))
l = list(map(str,input().split(" ")))

a = m

while 1:
    for i in str(a):
        if i in l:
            a += 1
            break
        else:
            print(a)
            exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d = list(map(int,input().split()))
#print(d)
for i in range(n,10000):
    count=0
    for j in range(k):
        u = str(d[j])
        if(str(n).count(u)==0):
            count+=1
    #print("count:"+str(count))
    n+=1
    if(count==k):
        break
print(i)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d = list(map(int,input().split()))
#print(d)
for i in range(n,10000):
    count=0
    for j in range(k):
        u = str(d[j])
        if(str(i).count(u)==0):
            count+=1
    #print("count:"+str(count))
    if(count==k):
        break
print(i)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d = list(map(int,input().split()))
#print(d)
for i in range(n,10000):
    count=0
    for j in range(k):
        u = d[j]
        if(str(u) in str(i) == False):
            count+=1
    if(count==k):
        break
print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
 
ans = len(t)
n_1 = len(s) - len(t)
n_2 = len(t)
 
tmp = 0
for i in range(n_1 + 1):
    tmp = 0
    for j in range(n_2):
        if s[i + j] != t[j]:
            tmp += 1
    ans = min(ans, tmp)
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,10000):
    count=0
    for j in range(k):
        u = d[j]
        if(str(i).count(str(u))==0):
            count+=1
    if(count==k):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[x]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
while y > 0:
    s = ans[y][0]
    t = ans[y][1]
    r = ans[y]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + int(s))
    if int(ans[y-1]) in D:
        u = int(ans[y-1])
        while u in D:
            u += 1
            ans[y-1] = str(u)
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y] = r
print("".join(ans))

Submission status: Wrong Answer

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

def find_ok( x , Oks ):
    for i in Oks:
        if int(i) > int(x):
            break
    return i

def main():
    n,k = map( str , input().split() )
    Nos = list(map( str , input().split() ))
    Oks = []
    for i in range(10):
        if str(i) not in Nos:
            Oks.append( str(i) )
    n = list(n)
    ans = []

    flag = 1
    for x in n:
        if flag == 1:
            if x in Nos:
                x = find_ok( x , Oks )
                flag = 0
            ans.append(x)
        else:
            if x in Nos:
                x = Oks[0]
            ans.append( x )
    
    print( ''.join(ans) )
main()

Submission status: Wrong Answer

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

def find_ok( x , Oks ):
    for i in Oks:
        if int(i) > int(x):
            break
    return i

def main():
    n,k = map( str , input().split() )
    Nos = list(map( str , input().split() ))
    Oks = []
    for i in range(10):
        if str(i) not in Nos:
            Oks.append( str(i) )
    n = list(n)
    ans = []

    flag = 1
    for x in n:
        if flag == 1:
            if x in Nos:
                x = find_ok( x , Oks )
                flag = 0
            ans.append(x)
        else:
            ans.append( Oks[0] )
    
    print( ''.join(ans) )
main()

Submission status: Wrong Answer

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

def find_ok( x , Oks ):
    for i in Oks:
        if int(i) > int(x):
            break
    return i

def main():
    n,k = map( str , input().split() )
    Nos = list(map( str , input().split() ))
    Oks = []
    for i in range(10):
        if str(i) not in Nos:
            Oks.append( str(i) )
    n = list(n)
    ans = []
    for x in n:
        if x in Nos:
            x = find_ok( x , Oks )
        ans.append(x)
    
    print( ''.join(ans) )
main()

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[0]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
while y != 0:
    s = ans[y][0]
    t = ans[y][1]
    r = ans[y]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + int(s))
    if int(ans[y-1]) in D:
        u = int(ans[y-1])
        while u in D:
            u += 1
            ans[y-1] = str(u)
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y] = r
print("".join(ans))

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[0]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
while y != 0:
    s = ans[y][0]
    t = ans[y][1]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + int(s))
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y][0] = s
        ans[y][0] = t
print("".join(ans))

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
c = 2
while c in D:
    c += 1
y = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        y = x
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[0]):
        for i in range(len(N)-1-x):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
print(ans)
while y != 0:
    s = ans[y][0]
    t = ans[y][1]
    ans[y] = t
    ans[y-1] = str(int(ans[y-1]) + int(s))
    if ans[y-1] != "10":
        y = 0
    else:
        y -= 1
        ans[y][0] = s
        ans[y][0] = t
print("".join(ans))

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
b = 0
while b in D:
    b += 1
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    if  a == 10:
        if 0 in D:
            a += b
        if 1 in D:
            if b != 0:
                a += (b-1)*10
            else:
                c = 2
                while c in D:
                    c += 1
                a += (c-1)*10
    ans.append(str(a))
    if a != int(N[0]):
        for i in range(len(N)-1):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
print("".join(ans))

Submission status: Wrong Answer

Solution code:
N,K = input().split()
D =list(map(int,input().split()))
ans = []
a = int(N[0])
x = 0
while a == int(N[x]) and x <= len(N)-1:
    while a in D and a <= 9:
        a += 1
    ans.append(str(a))
    if a != int(N[0]):
        b = 0
        while b in D:
            b += 1 
        for i in range(len(N)-1):
            ans.append(str(b))
    elif x <= len(N)-2:
        x += 1
        a = int(N[x])
    else:
        a = int(N[x])-1
print("".join(ans))

Submission status: Wrong Answer

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

ans = 0
flag1 = True
n = N%10
for i in range(n, 10):
  if i not in s:
    ans += i
    flag1 = False
    break
if flag1:
  for i in range(n):
    if i not in s:
      ans += i

N = (N-N%10) // 10
if N == 0:
  print(ans)
  exit()
n = N%10
flag2 = True
if flag1:
  for i in range(n+1, 10):
    if i not in s:
      ans += i*10
      flag2 = False
      break
  if flag2:
    for i in range(n+1):
      if i not in s:
        ans += i*10
else:
  for i in range(n, 10):
    if i not in s:
      ans += i*10
      flag2 = False
      break
  if flag2:
    for i in range(n):
      if i not in s:
        ans += i*10
        
N = (N-N%10) // 10
if N == 0:
  print(ans)
  exit()
n = N%10
flag3 = True
if flag2:
  for i in range(n+1, 10):
    if i not in s:
      ans += i*100
      flag3 = False
      break
  if flag3:
    for i in range(n+1):
      if i not in s:
        ans += i*100
else:
  for i in range(n, 10):
    if i not in s:
      ans += i*100
      flag3 = False
      break
  if flag3:
    for i in range(n):
      if i not in s:
        ans += i*100
        
N = (N-N%10) // 10
if N == 0:
  print(ans)
  exit()
n = N%10
flag4 = True
if flag3:
  for i in range(n+1, 10):
    if i not in s:
      ans += i*1000
      flag4 = False
      break
  if flag4:
    for i in range(n+1):
      if i not in s:
        ans += i*1000
else:
  for i in range(n, 10):
    if i not in s:
      ans += i*1000
      flag4 = False
      break
  if flag4:
    for i in range(n):
      if i not in s:
        ans += i*1000
print(ans)

Submission status: Wrong Answer

Solution code:
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
import datetime
# import webbrowser

# f = open("input.txt", 'r')
# g = open("output.txt", 'w')
# n, m = map(int, f.readline().split())

n, k = map(int, input().split())
dislike = list(map(int, input().split()))
like = []
for i in range(0, 10):
    if i not in dislike:
        like.append(i)
new = ""
for i in str(n):
    if int(i) not in dislike:
        new += str(i)
    else:
        for j in like:
            if j > int(i):
                new += str(j)
                break
print(new)

Submission status: Wrong Answer

Solution code:
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
import datetime
# import webbrowser

# f = open("input.txt", 'r')
# g = open("output.txt", 'w')
# n, m = map(int, f.readline().split())

n, k = map(int, input().split())
dislike = list(map(int, input().split()))
like = [i for i in range(10) if i not in dislike]
n = str(n)
new = ""
like.sort()
for i in n:
    if int(i) not in dislike:
        new += i
    else:
        for j in like:
            if j > int(i):
                new += str(j)
                break
print(new)

Submission status: Wrong Answer

Solution code:
def dfs(A: list):
    if len(A) > nn:
        return
    if len(A) and (x := int("".join(A))) >= n and ans[0] > x:
        ans[0] = x
        return

    for v in d:
        if v == "0" and len(A) == 0:
            next
        A.append(v)
        dfs(A)
        A.pop()


n, k = map(int, input().split())
d = sorted(list(set([str(i) for i in range(10)]) - set(input().split())))
nn = len(str(n))+1
ans = [10**7]
dfs([])
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def main():
	N, K = [int(n) for n in input().split(" ")]
	D = [1] * 10
	for d in input().split(" "):
		D[int(d)] = 0
	L = [str(i) for i, v in enumerate(D) if v == 1]

	digit = len(str(N))
	cand = []
	for n in list(itertools.product(L, repeat=digit)):
		p = int("".join(list(n)))
		if p >= N:
			cand.append(p)
	if len(cand):
		print(min(cand))
	else:
		if L[0] == 0:
			print(str(L[1]) + "0" * digit)
		else:
			print(str(L[0]) * (digit + 1))


main()

Submission status: Wrong Answer

Solution code:
total, k = map(int, input().split())

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

def total_to_digits(total):
    return map(int, list(str(total)))

def find_lowest_denomination(total, d):
    res = None
    for i in range(total, 10001):
        digits = list(total_to_digits(i))
        if not (set(digits) & set(d)):
            print(i)
            return


find_lowest_denomination(total, d)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
D = input().split()

for payment in range(N, 10000):
    if all(char not in D for char in str(payment)):
        print(payment)
        break

Submission status: Wrong Answer

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

inf = float('inf')
min_cost = inf
for amount in range(n, 100000):
    for e in arr:
        if str(e) in str(amount):
            break
        min_cost = min(min_cost, amount)

print(min_cost)

Submission status: Wrong Answer

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


min_cost = 1 << 60
for amount in range(n, 100000):
    for e in arr:
        if str(e) in str(amount):
            break
        min_cost = min(min_cost, amount)

print(min_cost)

Submission status: Wrong Answer

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


min_cost = 1 << 60
for amount in range(n, 100001):
    for e in arr:
        if str(e) in str(amount):
            break
        min_cost = min(min_cost, amount)

print(min_cost)

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/08/25

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,K=map(int,pin().split())
  D=list(map(int,pin().split()))
#   l=[0,1,2,3,4,5,6,7,8,9]
#   for i in D:
#     l.remove(i)
  j=N
  while j<=2*N:
    for k in str(j):
      if int(k) in D:
        break
    else:
      print(j)
      break
    j+=1
  return 
main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [i for i in range(10) if i not in A]
ANS = 0
c = 0
i = 0
while N:
  n = N % 10
  N //= 10
  flag = 0
  for b in B:
    if b >= n + c:
      ANS += b * 10 ** i
      flag = 1
      c = 0
      break
  if flag == 0:
    ANS += B[0] * 10 ** i
    c = 1
  i += 1
if c == 1:
  for b in B:
    if b != 0:
      ANS += b * 10 ** i
      break
print(ANS)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [i for i in range(10) if i not in A]
ANS = 0
c = 0
i = 0
while N:
  n = N % 10
  N //= 10
  flag = 0
  for b in B:
    if b >= n + c:
      ANS += b * 10 ** i
      flag = 1
      c = 0
      break
  if flag == 0:
    ANS += B[0] * 10 ** i
    c = 1
  i += 1
print(ANS)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [i for i in range(10) if i not in A]
ANS = 0
c = 0
i = 0
while N:
  n = N % 10
  N //= 10
  flag = 0
  for b in B:
    if b >= n + c:
      ANS += b * 10 ** i
      flag = 1
      break
  if flag == 0:
    ANS += B[0] * 10 ** i
    c = 1
  i += 1
print(ANS)

Submission status: Wrong Answer

Solution code:
total, k = map(int, input().split())

d = input().split()

def find_lowest_denomination(total, d):
    r = ""
    for c in str(total):
        c_temp = int(c)
        while str(c_temp) in d:
            c_temp += 1
        r = r + str(c_temp)
    print(r)

find_lowest_denomination(total, d)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement
n, k = map(int, input().split())
d = [int(x) for x in input().split()]
dd = set(list(range(10))) - set(d)

x = str(n)
lst = []
dd = list(dd)
dd.sort()
sel = []
for i in dd:
    if int(x[0]) <= i and len(sel) < 3: sel.append(i*10**(len(x)-1))
if len(sel) < 2:
    if len(dd) == 1:
        sel.append((dd[0]*10 + dd[0])* 10 ** (len(x)-1))
    else:
        if dd[0] != 0:
            sel.append((dd[0]*10 + dd[1])* 10 ** (len(x)-1))
        else:
            sel.append((dd[1]*10 + dd[0])* 10 ** (len(x)-1))

for j in sel:
    for l in combinations_with_replacement(dd, len(x)-1):
        cnt = j
        for i in range(len(x)-1):
            cnt += 10 ** (len(x)-i-2) * l[i]
        if cnt >= n: lst.append(cnt)
print(min(lst))

Submission status: Wrong Answer

Solution code:
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = LI()
d.sort()
d = list(map(str, d))
money = n
s_money = str(money)
is_ok = True
for c in s_money:
    if c in d:
        is_ok = False
        break
if is_ok:
    print(money)
    exit()

nums = list(map(str, range(10)))
s_money = list(s_money)[::-1]
for i, c in enumerate(s_money):
    if c not in d:
        continue
    for j in nums:
        if i < len(s_money)-1:
            if j not in d:
                s_money[i] = j
                break
        else:
            if j != '0' and j not in d:
                s_money[i] = j
                if int(''.join(s_money[::-1])) > money:
                    break

s_money = ''.join(s_money[::-1])
print(s_money)

Submission status: Wrong Answer

Solution code:
N,K = (int(T) for T in input().split())
D = input().split()
for TN in range(N,10000):
    StrN = str(TN)
    Flag = True
    for TS in StrN:
        if TS in D:
            Flag = False
            break
    if Flag:
        print(TN)
        break

Submission status: Wrong Answer

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

kari = 0
N = N - 1
num_list.append(input().split())
num_list_3 = sorted(num_list)
while(kari != 1):
    count = 0
    N =N + 1 
    for i in range(K - 1):
        a = num_list_3[0][i]
        s = str(N).count(a)
        print(s)
        if(s != 0):
            count= count + 1
            print(count)  
    if (count == 0):
        kari = 1
print(N)

Submission status: Wrong Answer

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

kari = 0
N -= 1
num_list.append(input().split())
num_list_3 = sorted(num_list)
while(kari != 1):
    count = 0
    N += 1 
    for i in range(K - 1):
        a = num_list_3[0][i]
        s = str(N).count(a)
        print(s)
        if(s != 0):
            count+= 1
            print(count)  
    if (count == 0):
        kari = 1
print(N)

Submission status: Wrong Answer

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

m=1
while m<=len(str(N)):
    while str(N)[-m] in D:
        N+=10**(m-1)
    m+=1
print(N)

Submission status: Wrong Answer

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

d = set()
for i in range(K):
    d.add(str(D[i]))
print(d)

for i in range(N, 100000):
    s = str(i)
    li = list(s)
    nowset = set(li)
    if not nowset & d:
        print(i)
        exit()

Submission status: Wrong Answer

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

d = set()
for i in range(K):
    d.add(str(D[i]))
# print(d)

for i in range(N, 10000):
    flag = True
    s = str(i)
    li = list(s)
    for nowletter in li:
        if nowletter in d:
            flag = False
    if flag:
        print(i)
        exit()

Submission status: Wrong Answer

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

d = set()
for i in range(K):
    d.add(str(D[i]))
# print(d)

for i in range(N, 10001):
    s = str(i)
    li = list(s)
    nowset = set(li)
    if not nowset & d:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))

result = []
for i in price:
    for j in ok_num:
        if i <= j:
            result.append(j)
            break

print(''.join(result))

Submission status: Wrong Answer

Solution code:
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))
print(ok_num)

result = []
for i in price:
    for j in ok_num:
        if i <= j:
            result.append(j)
            break

print(''.join(result))

Submission status: Wrong Answer

Solution code:
price, hate = input().split()
no_num = set([x for x in input().split()])
ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num))
print(ok_num)

result = []
for i in price:
    print(i)
    for j in ok_num:
        if i <= j:
            result.append(j)
            break

print(''.join(result))

Submission status: Wrong Answer

Solution code:
import string

def main():

    N, K = input().split()

    bad_n = input().replace(' ', '')

    ans = []
    temp = 0
    temp2 = ''
    for i in N:
        for j in string.digits:
            if j not in bad_n:
                if int(j) == int(i):
                    temp2 = j
                    break
                elif int(j) > temp:
                    temp = int(i)
                    temp2 = j
                    break
        ans.append(temp2)
        
    if int("".join(ans)) < int(N):
        ans.append(temp2)


    print("".join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import string

def main():

    N, K = input().split()

    bad_n = input().replace(' ', '')

    ans = []
    temp = 0
    temp2 = ''
    for i in N:
        for j in string.digits:
            if j not in bad_n:
                if int(j) == int(i):
                    temp2 = j
                    break
                elif int(j) > temp:
                    temp = int(i)
                    temp2 = j
        ans.append(temp2)

    print("".join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

C = list({0,1,2,3,4,5,6,7,8,9}-D)
C.sort()
num = len(N)

def minimum(x,ans):
    ans += str(min(C))*x
    return ans

ans = ''
if C[-1]<int(N[0]):    
    C_0 = list(set(C)-{0})
    ans += str(min(C_0))
    ans = minimum(num,ans)
    print(ans)
    exit()

for i in range(0,num):
    for j in range(len(C)):
        if C[j]==int(N[i]):
            ans += str(C[j])
            break
        elif C[j]>=int(N[i]):
            ans += str(C[j])
            ans = minimum(num-i-1,ans)
            print(int(ans))
            exit()

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    D = set(input().split())
    for I in range(N,10**4+1):
        if set(str(I)).isdisjoint(D):
            print(I)
            break


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans=0
flg=False
for i in range(n,10*n+1):
    for j in d:
        if j in str(i):
            break
        flg=True
    if flg:
        ans=i
        break
print(ans)

Submission status: Wrong Answer

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

ans=0
flg=False
for i in range(n,88889):
    for j in d:
        if j in str(i):
            break
        ans=i
        flg=True
    if flg:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, _ = input().split()
N = int(N)
dislike = list(map(int, input().split()))
like = []
ans = []
t = 0
a = N
f = True
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
x = N
for i in l:
    if i not in dislike:
        like.append(i)
like = list(str(like))
dislike = list(str(dislike))
while f:
    x = list(str(x))
    for i in x:
        if i not in dislike:
            f = False
        else:
            f = True
        break
    x = int("".join(x)) + 1


x -= 1
print(x)

Submission status: Wrong Answer

Solution code:
N, _ = input().split()
N = int(N)
dislike = list(map(int, input().split()))
like = []
ans = []
t = 0
a = N
f = True
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
x = N
for i in l:
    if i not in dislike:
        like.append(i)
like = list(str(like))
while f:
    x = list(str(x))
    for i in x:
        if i in like:
            f = False
        else:
            f = True
        break
    x = int("".join(x)) + 1


x -= 1
print(x)

Submission status: Wrong Answer

Solution code:
N, _ = input().split()
dislike = list(map(int, input().split()))
like = []
ans = []
price = list(N)
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in l:
    if i not in dislike:
        like.append(i)
like.sort()
price.reverse()
for i in price:
    mn = min(like)
    for k in like:
        if int(i) <= k:
            ans.append(k)
            break
        elif int(i) > k:
            for j in like:
                if int(i) <= j:
                    ans.append(j)
            break
ans = list(map(str, ans))
ans.reverse()
a = "".join(ans)
print(a)

Submission status: Wrong Answer

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-13 22:50
# @url:https://atcoder.jp/contests/abc042/tasks/arc058_a

import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n,k=map(int,input().split())
    d=list(map(int,input().split()))
    mx=10000
    ans=10000
    while mx>=0:
        temp=str(mx)
        f=True
        for i in range(len(temp)):
            if int(temp[i]) in d:
                f=False
                break
        if f and mx>=n:
            ans=min(ans,mx)
        mx=mx-1
    print (ans)

if __name__ == "__main__":
    main()