Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

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

Input

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

N K
D_1 D_2 … D_K

Output

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

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

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

Sample Input 2

9999 1
0

Sample Output 2

9999



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


Sample output:
2000

Submission status: Wrong Answer

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

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

N = str(N)
K = 10 - K

ans = ''
check = False

for i in range(K):
    if d[i] >= int(N[0]):
        ans += str(d[i])
        if d[i] != int(N[0]):
            check = True
        break
    if i == K - 1:
        t = 0
        if d[0] == 0:
            t = 1
        ans += str(d[t]) + str(d[0])
        check = True

for i in range(1, len(N)):
    if check:
        ans += str(d[0])
    else:
        for j in range(K):
            if d[j] >= int(N[i]):
                ans += str(d[j])
                if d[j] != int(N[i]):
                    check = True
                break

print(ans)

Submission status: Wrong Answer

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

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

N = str(N)
K = 10 - K

ans = ''
check = False

for i in range(K):
    if d[i] >= int(N[0]):
        ans += str(d[i])
        if d[i] != int(N[0]):
            check = True
        break
    if i == K - 1:
        t = 0
        if d[0] == 0:
            t = 1
        ans += str(d[t]) + str(d[0])
        check = True

for i in range(1, len(N)):
    if check:
        ans += str(d[0])
    else:
        for j in range(K):
            if d[j] >= int(N[i]):
                ans += str(d[j])
                if d[j] != int(N[i]):
                    check = True
                    break

print(ans)

Submission status: Wrong Answer

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

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

N = str(N)
K = 10 - K

ans = ''
check = False

for i in range(K):
    if d[i] >= int(N[0]):
        ans += str(d[i])
        if d[i] != int(N[0]):
            check = True
        break
    if i == K - 1:
        ans += str(d[0])*2
        check = True

for i in range(1, len(N)):
    if check:
        ans += str(d[0])
    else:
        for j in range(K):
            if d[j] >= int(N[i]):
                ans += str(d[j])
                if d[j] != int(N[i]):
                    check = True
                    break

print(ans)

Submission status: Wrong Answer

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

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

N = str(N)
K = 10 - K

ans = ''
check = False

for i in range(K):
    if d[i] >= int(N[0]):
        ans += str(d[i])
        if d[i] != int(N[0]):
            check = True
        break

for i in range(1, len(N)):
    if check:
        ans += str(d[0])
    else:
        for j in range(K):
            if d[j] >= int(N[i]):
                ans += str(d[j])
                if d[j] != int(N[i]):
                    check = True
                    break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n,k = map(int,input().split())
a = list(map(str,input().split()))
d = [str(i) for i in range(10)]

for c in a:
    d.remove(c)

res = -1
for l in itertools.product(d,repeat=len(str(n))):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
if res != -1:
    print(res)
    exit(0)
for l in itertools.product(d,repeat=len(str(n))):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
print(res)

Submission status: Wrong Answer

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

dit = list(range(10))
for c in a:
    dit.remove(c)

n = str(n)
f = n[0]
ff = 0
for d in dit:
    if d>=int(f):
        ff = d
        break
res = ""

if ff!=0:
    res+=str(ff)
    for i in range(len(n)-1):
        ff = -1
        for d in dit:
            if d>=int(n[i+1]):
                ff = d
                break
        if ff == -1:
            res = ""
            break
        else:
            res+=str(ff)
if res=="":
    for d in dit:
        if d!=0:
            ff = d
            break
    res+=str(ff)
    for i in range(len(n)):
        res+=str(dit[0])
 
print(res)

Submission status: Wrong Answer

Solution code:
def pay_by_iroha(price, dislike_digits):
    for n in range(10000):
        if n >= price and len(set(int(i) for i in str(n))&dislike_digits)==0:
            return n


def main():
    n = 1000
    dislike_ds = {1, 3, 4, 5, 6, 7, 8, 9}
    print(pay_by_iroha(n, dislike_ds))


main()

Submission status: Wrong Answer

Solution code:
def pay_by_iroha(price, dislike_digits):
    for n in range(10000):
        if n >= price and not set(str(price)) & dislike_digits:
            return n


def main():
    n, _ = (int(i) for i in input().split())
    dislike_ds = set([int(i) for i in input().split()])
    print(pay_by_iroha(n, dislike_ds))


main()

Submission status: Wrong Answer

Solution code:
import itertools
 
white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.product(white_num_list, repeat = len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
    
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    placeholder = str(min(white_num_list)) * (len(str(N)) + 1)
    if placeholder[0] == '0':
        white_num_list.remove(0)
        print(white_num_list)
        placeholder = str(min(white_num_list)) + placeholder[1:]
    return int(placeholder)
      
print(price(N, num_list, white_num_list))

Submission status: Wrong Answer

Solution code:
import itertools

white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))

white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.product(white_num_list, repeat = len(str(N))))

num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
    
num_list = sorted(num_list)

def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    placeholder = str(min(white_num_list)) * (len(str(N)) + 1)
    if placeholder[0] == '0':
        white_num_list.remove(0)
        print(white_num_list)
        placeholder = str(min(white_num_list)) + placeholder[1:]
        return int(placeholder)
      
print(price(N, num_list, white_num_list))

Submission status: Wrong Answer

Solution code:
import itertools

white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.combinations_with_replacement(white_num_list, len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
 
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    if 0 in white_num_list:
        white_num_list.remove(0)
    placeholder = str(min(white_num_list))
    return int(placeholder * (len(str(N)) + 1))
  
print(price(N, num_list, white_num_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flag = False
for a in range(N, 10000):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [str(i) for i in input().split()]
for i in range(1, 20):
    ans = n * i
    if len(set(list(str(ans))) & set(d)) == 0:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(' '))
d_list = input().split(' ')
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                number =  i * 1000 + j * 100 + k * 10 + l
                result = set(list(str(number)))
                if set(d_list) & result != set():
                    continue
                if number >= N:
                    print(number)
                    break
            else:
                continue
            break
        else:
            continue
        break
    else:
        continue
    break

Submission status: Wrong Answer

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

for i in range(N, 10*N+1):
    elem = set()
    n = i
    for _ in range(4):
        e = n % 10
        elem.add(e)
        n //= 10
    if len(set(D) & elem) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

for i in range(N, 100000):
    elem = set()
    n = i
    for _ in range(4):
        e = n % 10
        elem.add(e)
        n //= 10
    if len(set(D) & elem) == 0:
        print(i)
        break

Submission status: Wrong Answer

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

for i in range(N, 10000):
    elem = set()
    n = i
    for _ in range(4):
        e = n % 10
        elem.add(e)
        n //= 10
    if len(set(D) & elem) == 0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def main():
	N, K = map(int, input().split())
	D = list(map(int, input().split()))
	rec = 0
	rec2 = 1
	for d in D:
		if rec != d:
			break
		rec += 1
	for d in D:
		if rec2 != d:
			break
		rec2 += 1

	strN = str(N)
	carry = False
	ans = ""
	for i in range(len(strN)-1, -1, -1):
		cur = int(strN[i])
		if carry:
			cur += 1
			carry = False
			if cur == 10:
				carry = True
		while cur in D:
			cur += 1
			if cur == 10:
				cur = 0
				carry = True
		if carry:
			ans = str(rec)*(len(strN)-i)
		else:
			ans = str(cur)+ans
	if carry:
		ans = str(rec)*(len(strN))
		if rec == 0:
			ans = str(rec2) + ans
		else:
			ans = str(rec) + ans

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	N, K = map(int, input().split())
	D = list(map(int, input().split()))
	rec = 0
	for d in D:
		if rec != d:
			break
		rec += 1

	strN = str(N)
	carry = False
	ans = ""
	for i in range(len(strN)-1, -1, -1):
		cur = int(strN[i])
		if carry:
			cur += 1
			carry = False
			if cur == 10:
				carry = True
		while cur in D:
			cur += 1
			if cur == 10:
				cur = 0
				carry = True
		if carry:
			ans = str(rec)*(len(strN)-i)
		else:
			ans = str(cur)+ans
	if carry:
		ans = str(rec)*(len(strN)+1)

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	N, K = map(int, input().split())
	D = list(map(int, input().split()))
	rec = 0
	for d in D:
		if rec != d:
			break
		rec += 1

	strN = str(N)
	carry = False
	ans = ""
	for i in range(len(strN)-1, -1, -1):
		cur = int(strN[i])
		if carry:
			cur += 1
			carry = False
		while cur in D:
			cur += 1
			if cur == 10:
				cur = 0
				carry = True
		if carry:
			ans = str(rec)*(len(strN)-i)
		else:
			ans = str(cur)+ans
	if carry:
		ans = str(rec)*(len(strN)+1)

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

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

pay = n
disLike = True

while disLike:
    for i in range(10):
        pay += 1
        disLike = False
        for j in range(len(str(pay))):
            if str(pay)[j] in nums:
                disLike = True

print(pay)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [str(i) for i in input().split()]
for i in range(1, 11):
    ans = n * i
    if len(set(list(str(ans))) & set(d)) == 0:
        print(ans)
        break

Submission status: Wrong Answer

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

import sys

for i in range (N, 10**4+1):
    if len(set(list(str(i))) & set(D)) == 0:
        print(i)
        sys.exit()

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists=list(map(str,input().split()))

for i in range(int(N),10000):
    flg=True
    for j in str(i):
        if j in lists: 
            flg = False
            break
    if flg:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists=list(map(str,input().split()))
flg=False

for i in range(int(N),10000):
    flg=True
    for j in str(i):
        if j in lists: 
            flg = False
            break
    if flg:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def D2NC(D: int, N: int, link=False) -> list:
    alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    res = []
    while D > 0:
        if D % N > 9:
            tmp = alp[D % N - 10]
            res.insert(0, str(tmp))
        else:
            res.insert(0, str(D % N))
        D //= N
    if not res:
        res.append('0')
    if link:
        res = ''.join(res)
    return res


N, K = map(int, input().split())
D = [int(i) for i in input().split()]

usable = []
for i in range(10):
    if i not in D:
        usable.append(str(i))

num = 1
while True:
    ans = []
    tmp = D2NC(num, len(usable), link=True)
    for i in tmp:
        i = int(i)
        ans.append(usable[i])
    ans = int(''.join(ans))
    if ans >= N:
        break
    num += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
flg=False

for i in s:
    lists.remove(i)

for i in N:
    for n,j in enumerate(lists):
        if flg:
            price+=str(lists[0])
            break
        if int(i) <= int(j):
            price+=str(j)
            break
        if len(lists)==n+1:
            price+=str(lists[0])
            flg=True
#先頭0の場合
if lists[0]==0: lists.remove(0)
#繰り上がりの場合
if flg: price=str(lists[0])+price

print(price)

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
flg=False

for i in s:
    lists.remove(i)

for i in N:
    for n,j in enumerate(lists):
        if int(i) <= int(j):
            price+=str(j)
            break
        if len(lists)==n+1:
            price+=str(lists[0])
            flg=True
#先頭0の場合
if lists[0]==0: lists.remove(0)
#繰り上がりの場合

if flg: price=str(lists[0])+str(price)

print(price)

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
flg=False

for i in s:
    lists.remove(i)

for i in N:
    for n,j in enumerate(lists):
        if int(i) <= int(j):
            price+=str(j)
            print(price)
            break
        if len(lists)==n:
            price+=str(lists[0])
            flg=True
#先頭0の場合
if lists[0]==0: lists.remove(0)
#繰り上がりの場合
if flg: price=str(lists[0])+price

print(price)

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
flg=False

for i in s:
    lists.remove(i)

for i in N:
    for j,n in enumerate(lists):
        if int(i) <= int(j):
            price+=str(j)
            break
        if len(lists)==n:
            price+=str(lists[0])
            flg=True
#先頭0の場合
if lists[0]==0: lists.remove(0)
#繰り上がりの場合
if flg: price=str(lists[0])+price
  
print(price)

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
flg=False

for i in s:
    lists.remove(i)

for i in N:
    for j,n in enumerate(lists):
        if int(i) <= int(j):
            price+=str(j)
            break
        if len(lists)==n:
            price+=str(lists[0])
            flg=True
#先頭0の場合
if lists[0]==0: lists.remove(0)
#繰り上がりの場合
if flg: price=str(lists[0])+price

Submission status: Wrong Answer

Solution code:
N,_ = map(str,input().split())
lists = [0,1,2,3,4,5,6,7,8,9]
s=list(map(int,input().split()))
price=""
for i in s:
    lists.remove(i)

for i in N:
    for j in lists:
        if int(i) <= int(j):
            price+=str(j)
            break
print(price)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D = input().split()
for ans in range(N, 10000):
    if len(list(set(str(ans)) & set(D))) == 0:
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = set([str(i) for i in input().split()])
c = 0
ans = 0
for i in range(1, 11):
    c += n
    t = set(list(str(c)))
    if len(t & d) == 0:
        ans = c
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

p = []
for i in range(0, 10):
    if i in a:
        pass
    else:
        p.append(i)
p.sort()
count = 0
for i in list(n):
    count *= 10
    for j in p:
        if int(i) <= int(j):
            count += int(j)
            break
            
print(count)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

p = []
for i in range(0, 10):
    if i in a:
        pass
    else:
        p.append(i)
p.sort()
count = 0
for i in list(n):
    count *= 10
    for j in p:
        if int(i) <= int(j):
            count += int(j)
            
print(count)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
n_list=[]
while True:
    if n==0:
        break
    else:
        n_list.append(n%10)
        n//=10
n_list.append(0)
n_list=n_list[::-1]
for i in range(len(n_list)):
    if n_list[-1-i]==10:
            n_list[-1-i]=0
            n_list[-2-i]+=1
    while n_list[-1-i] in d:
        if i==len(n_list)-1 and n_list[-1-i]==0:
            break
        if n_list[-1-i]==9:
            n_list[-1-i]=0
            n_list[-2-i]+=1
        else:
            n_list[-1-i]+=1
for i in range(len(n_list)):
    n_list[i]=str(n_list[i])
if n_list[0]=="0":
    print("".join(n_list[1:]))
else:
    print("".join(n_list))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
n_list=[]
while True:
    if n==0:
        break
    else:
        n_list.append(n%10)
        n//=10
n_list.append(0)
n_list=n_list[::-1]
print(n_list)
for i in range(len(n_list)):
    if n_list[-1-i]==10:
            n_list[-1-i]=0
            n_list[-2-i]+=1
    while n_list[-1-i] in d:
        if i==len(n_list)-1 and n_list[-1-i]==0:
            break
        if n_list[-1-i]==9:
            n_list[-1-i]=0
            n_list[-2-i]+=1
        else:
            n_list[-1-i]+=1
for i in range(len(n_list)):
    n_list[i]=str(n_list[i])
if n_list[0]=="0":
    print("".join(n_list[1:]))
else:
    print("".join(n_list))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
n_list=[]
while True:
    if n==0:
        break
    else:
        n_list.append(n%10)
        n//=10
n_list.append(0)
n_list=n_list[::-1]
for i in range(len(n_list)):
    while n_list[-1-i] in d:
        if i==len(n_list)-1 and n_list[-1-i]==0:
            break
        if n_list[-1-i]==9:
            n_list[-1-i]=0
            n_list[-2-i]+=1
        else:
            n_list[-1-i]+=1
for i in range(len(n_list)):
    n_list[i]=str(n_list[i])
if n_list[0]=="0":
    print("".join(n_list[1:]))
else:
    print("".join(n_list))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
m=list(map(int,input().split()))
for i in range(n,100000):
  k=1
  for a in str(i):
    if a in m:
      k=0
  if k:
    print(i)
    break

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(10):
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        for e in m:
          num=a*10000+b*1000+c*100+d*10+e
          if k==0 and num>=n:
            print(num)
            k=1

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[]
for i in range(10):
  if i not in a:
    m.append(i)
k=0
for a in m:
  for b in m:
    for c in m:
      for d in m:
        num=a*1000+b*100+c*10+d
        if k==0 and num>=n:
          print(num)
          k=1

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(str,input().split()))
for i in range(N, 10*N+1):
  if N<=i:
    ans=""
    for j in str(i):
      if j not in D:
        ans+=j
        if len(ans)==len(str(N)):
          print(i)
          exit()

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
D = list(map(str,input().split()))
for i in range(N, 10*N+1):
  if N<=i:
    cnt = 0
    for j in str(i):
      if j in D:
        break
      else:
        cnt+=1
        if cnt==len(str(N)):
          print(i)
          exit()

Submission status: Wrong Answer

Solution code:
N,K = map(str,input().split())
D = list(map(int,input().split()))
nums = [x for x in range(10)]
nots = [i for i in nums if i not in D]
ans = ""
for j in range(len(N)):
  for k in nots:
    if int(N[j])<=k:
      ans+=str(k)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N, K = map(str, input().split())
    D = list(map(str, input().split()))

    nums = set([str(i) for i in range(10)])
    safe = list(nums - set(D))

    digit = len(str(N))
    safe_num = list(product(safe, repeat=digit+1))
    ans = 10**5
    for n in safe_num:
        m = int(''.join(n))
        if m >= int(N):
            ans = min(ans, m)

    return ans


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

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    safe = list(set(range(10)) - set(D))
    safe = sorted(safe)

    n = [c for c in str(N)]
    conv = -1
    for i in range(len(n)):
        if int(n[i]) in safe:
            continue
        
        for s in safe:
            if s > int(n[i]):
                n[i] = str(s)
                conv = i + 1
                break
        break

    if conv == -1 or conv >= len(n):
        return ''.join(n)

    for i in range(conv, len(n)):
        n[i] = str(safe[0])

    return ''.join(n)


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

Submission status: Wrong Answer

Solution code:
num =set([0,1,2,3,4,5,6,7,8,9])
n,k = input().split()
d = list(map(int,input().split()))
a = list(num - set(d))
a.sort()
ans =[]
for i in range(len(n)):
    for j in a:
        if int(n[i]) <= j:
            ans.append(j)
            break
    if a[-1] < int(n[i]):
        ans.append(a[0])
l = map(str,ans)
b = "".join(l)
if int(b) < int(n):
    if a[0] != 0:
        print(a[0]*(10**(len(n)))+int(b))
    else:
        print(a[1]*(10**(len(n))) + int(b))
else:
    print(int(b))

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    safe = list(set(range(10)) - set(D))
    safe = sorted(safe)

    n = [c for c in str(N)]
    for i in range(len(n)):
        if int(n[i]) in safe:
            continue
        
        for s in safe:
            if s > int(n[i]):
                n[i] = str(s)
                break
        break

    for i in range(len(n)):
        if int(n[i]) not in safe:
            n[i] = str(safe[0])


    return ''.join(n)


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

Submission status: Wrong Answer

Solution code:
def check(x,sample):
    x=str(x)
    for i in x:
        if i in sample:
            return False
    return True

def main():
    n,k=map(int,input().split())
    sample=input().split()
    for i in range(n,20000):
        if check(i,sample):
            print(i)
            return;
main()

Submission status: Wrong Answer

Solution code:
def check(x,sample):
    x=str(x)
    for i in x:
        if i in sample:
            return False
    return True

def main():
    n,k=map(int,input().split())
    sample=input().split()
    for i in range(n,11000):
        if check(i,sample):
            print(i)
            return;
main()

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
D=list(map(int,input().split()))
N=set(i for i in range(10))
C=list(N-set(D))
ans=float("inf")
for a in list(itertools.product(C,repeat=len(str(n)))):
  m=int("".join(map(str,a)))
  if m>=n:
    ans=min(ans,m)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n,k=map(int,input().split())
D=list(map(int,input().split()))
N=set(i for i in range(10))
C=list(N-set(D))
ans=float("inf")
for a in list(itertools.product(C,repeat=5)):
  m=int("".join(map(str,a)))
  if m>=n:
    ans=min(ans,m)
print(ans)

Submission status: Wrong Answer

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

for n in list(map(int, list(str(N)))):
    if n > use[-1]:
        ans+=str(use[0])
    else:
        for i in use:
            if i >= n:
                ans+=str(i)
                break
    

if N-int(ans) > 0:
    ans = str(use[0]) + str(use[0])*len(str(N)) if use[0]!=0 else str(use[1])+str(use[0])*len(str(N))

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
D=input().split()
print(D)
ans=N
while True:
  for i in str(ans):
    if i in D:
      break
  else:
    print(ans)
    exit()
  ans +=1

Submission status: Wrong Answer

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

ans=N
while True:
  for i in str(ans):
    if i in D:
      break
    else:
      print(ans)
      exit()
  ans +=1

Submission status: Wrong Answer

Solution code:
import sys

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

ans=N
while True:
  for i in str(ans):
    if i in D:
      break
    else:
      print(ans)
      sys.exit()
  ans +=1

Submission status: Wrong Answer

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

ans=N
while True:
  for i in str(ans):
    if i in D:
      break
    else:
      print(ans)
      exit()
    ans +=1

Submission status: Wrong Answer

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

for i in range(n, 10**5):
    if i < 10:
        if i % 10 in d:
            continue
    if i < 100:
        if i%10 in d:
            continue
        if i//10 in d:
            continue
    if i < 1000:
        if i//100 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    if i < 10000:
        if i//1000 in d:
            continue
        if (i//100)%10 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    else:
        if i//10000 in d:
            continue
        if (i//1000)%10 in d:
            continue
        if (i//100)%10 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    print(i)
    exit()

Submission status: Wrong Answer

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

while True:
    for i in str(ans):
        if i in d:
            break
    else:
        print(ans)
        exit()
    ans += 1

Submission status: Wrong Answer

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

for i in range(n, 10**5):
    if i < 10:
        if i % 10 in d:
            continue
    if i < 100:
        if i%10 in d:
            continue
        if i//10 in d:
            continue
    if i < 1000:
        if i//100 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    if i < 10000:
        if i//1000 in d:
            continue
        if (i//100)%10 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    if i >= 10000:
        if i//10000 in d:
            continue
        if (i//1000)%10 in d:
            continue
        if (i//100)%10 in d:
            continue
        if (i//10)%10 in d:
            continue
        if i%10 in d:
            continue
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
d = [i for i in input().split()]
t = n
while len(set(list(str(t))) & set(d)) > 0:
    t += n
print(t)

Submission status: Wrong Answer

Solution code:
n, k = (int(_) for _ in input().split())
a = [int(_) for _ in input().split()]
like = [i for i in range(10)]
pay = []
for i in a:
    like.remove(i)

for i in str(n):
    while int(i)%10 in a:
            i = int(i) + 1
    pay.append(str(int(i) % 10))
    
total = ''  
if pay[0] == '0':
    if like[0] == 0:
        pay[0] = str(like[1])
    else:
        pay[0] = str(like[0])
     
for i in pay:
    total += i
    
if n > int(total):
    total += str(like[0])
print(int(total))