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: Accepted

Solution code:
iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if  x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])

def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
    iL = len(sTarget)
    iF = int(sTarget[iPoint])
    aUpper = [x for x in aUnList if x >= iF]
    aUpper.sort()
    if bRev: #遡ってきたとき
        #もうひとつ上があるかどうか
        if len(aUpper) == 1 : #==のとき。もうひとつ上はない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])] * (iL + 1)
            else:
                return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
        else: #上の桁がある
            return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
    else: #順向
        if aUpper == []: #大きい数字がない
            if iPoint == 0:
                if aUnList[0] == 0:
                    return [str(aUnList[1])] + ["0"] * iL
                else:
                    return [str(aUnList[0])]*(iL+1)
            else:
                return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,True) #逆行する
        else:
            if aUpper[0] != iF:
                return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
            else:
                aRet.append(str(iF))
                if iPoint  < iL -1 :
                    return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False) #順行する
                else:
                    return aRet

print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = [str(_) for _ in input().split()]
Unable = set(D)

Fin = False
Ans = N
while not Fin:
    if not set(str(Ans)) & Unable:
        Fin = True
    else:
        Ans += 1

print(Ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
while True:
    p = 0
    for s in d:
        if str(s) in str(n):
            pass
        else:
            p += 1
    if p==k:
        print(n)
        break
    else:
        n += 1

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
lis = list(map(str,input().split()))
cou = n
while 1:
  for i in range(d):
    if lis[i] in str(cou):
      break
    if i == d-1:
      print(cou)
      exit()
  cou += 1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = N
while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = i // 10
    if i == 0:
        break
    n += 1
print(n)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]

for i in range(n, 100000):
    f = True
    for si in str(i):
        if int(si) in d:
            f = False
    if f:
        print(i)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
notD = [i for i in range(0, 10)]
for i in D:
    notD[i] = 10
i = 0
while True:
    if i >= len(notD):
        break
    if notD[i] == 10:
        del notD[i]
        i -= 1
    i += 1
i = N
while True:
    ans = 1
    for j in list(str(i)):
        for k in D:
            if int(j) == k:
                ans = -1
                break
        if ans == -1:
            break
    if ans == -1:
        i += 1
    elif ans == 1:
        print(i)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
inputs_set = set([i for i in input().split()])

all_set = set({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})
rest_set = all_set - inputs_set

for i in range(N, N*10 + 1):
    if set(str(i)) <= rest_set:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
for i in range(n, 10 * n + 1):
    flag = True
    q = str(i)
    for j in range(len(q)):
        if int(q[j]) in d:
            flag = False
            break
    if flag:
        print(i)
        break

Submission status: Accepted

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

start = N
while True:
    for num in str(start):
        if num in lst:
            break
    else:
        break
    start += 1
print(str(start))

Submission status: Accepted

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

n = N

while True:
    for c in str(n):
        if c in D:
            break
    else:
        break
    n += 1

print(n)

Submission status: Accepted

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

n = N

while True:
    for c in str(n):
        if c in D:
            break
    else:
        break
    n += 1

print(n)

Submission status: Accepted

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

n = N

while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = int(i / 10)
    if i == 0:
        break
    n += 1

print(n)

Submission status: Accepted

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

n = N

while True:
    i = n
    while i != 0:
        if i % 10 in D:
            break
        i = i // 10
    if i == 0:
        break
    n += 1

print(n)

Submission status: Accepted

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

n = N

while True:
    flg = False
    for Di in D:
        if str(Di) in str(n):
            flg = True
    if not flg:
        break
    n += 1

print(n)

Submission status: Accepted

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

while True:
    is_hate = False
    for digit in list(str(affordable)):
        if digit in hate_nums:
            is_hate = True
    if is_hate:
        affordable += 1
    else:
        print(affordable)
        break

Submission status: Accepted

Solution code:
from itertools import product

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


def check(x):
    for s in str(x):
        if int(s) in D:
            return False
    return True


for i in range(N, 10 * N):
    if check(i):
        print(i)
        break

Submission status: Accepted

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

for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for ni in n:
        if ni in D:
            flag = False
            break
    if flag:
        print(n)
        exit()

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
d=list(input().split())
x=n
while(1):
    j=False
    for t in list(str(x)):
        if t in d:
            j=True
    if j:
        x+=1
    else:
        print(x)
        break

Submission status: Accepted

Solution code:
a,b = map(int,input().split())

c = input().split()

while 1:
    f = 1
    s = str(a)
    for i in c:
        if i in s: f = 0
    if f : break
    a += 1
print(a)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
D = input().split()
ans = N
while 1:
    s = str(ans)
    f = 1
    for i in D:
        if i in s : f = 0
    if f : break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    D = input().split()
    ans = N
    while 1:
        s = str(ans)
        f = 1
        for i in D:
            if i in s : f = 0
        if f : break
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    D = input().split()
    ans = N
    while 1:
        s = str(ans)
        if not [1 for i in D if i in s] : break
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

n, k = map(int, input().split())
array = {x for x in input().split()}
num_array = {str(x) for x in range(10)}
like_num = array^num_array

res = float("inf")
for i in range(1, 100000):
    tmp = set(list(str(i)))
    if tmp.issubset(like_num):
        if n <= i < res:
            res = i
print(res)

Submission status: Accepted

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

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

for i in range(N, 100000):
    i = str(i)
    for j in range(K):
        if i.find(Dk[j]) != -1:
            break
        if j == K-1:
            print(i)
            exit()

Submission status: Accepted

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

while set(str(n)) & set(d):
	n += 1
print(n)

Submission status: Accepted

Solution code:
n=int(input().split()[0])
d=set(input())
while len(set(str(n))&d):
  n+=1
print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = input().split()
while len(set(str(n)) & set(d)) != 0:
  n += 1
print(n)

Submission status: Accepted

Solution code:
N, K=map(int,input().split())
D=list(map(int,input().split()))
ans=N
while ans<99999:
    flag=False
    num = list(map(int, str(ans)))
    for i in range(K):
        for digit in num:
            if digit==D[i]:
                ans +=1
                flag=True
                break
        if flag:
            break
    if flag==False:
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,K = inpl()
dd = inpl()

def check(N):
	tmp = list(map(int,list(str(N))))
	for t in tmp:
		if t in dd:
			return False
	return True

while True:
	if check(N):
		print(N)
		break
	N += 1

Submission status: Accepted

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

s = set(d)

N = str(n)
flag = 1
for i in N:
    if int(i) in s:
        flag = 0

if flag:
    print(n)
else:
    while True:
        n += 1
        N = str(n)
        flag = 1
        for i in N:
            if int(i) in s:
                flag = 0
        if flag:
            print(n)
            break

Submission status: Accepted

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

ans = 0

for i in range(N, 10*N+1):
    res = i
    while res > 0:
        digit = res % 10
        
        if digit in D:
            break
        
        res //= 10
        
    if res <= 0:
        ans = i   
        break

print(ans)

Submission status: Accepted

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

for i in range(N,INF):
	for d in D:
		if str(d) in str(i):
			break
	else:
		print(i)
		break
	#print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    #n, k = input().split()
    n, k = map(int, input().split())
    d_list = list(map(int, input().split()))

    while True:
        if all(x not in d_list for x in list(map(int, list(str(n))))):
            ans = n
            break
        n += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def solve(like_list, n, rp,  ans):
    for i in itertools.product(like_list, repeat=rp):
        if i[0] != 0:
            num = int(''.join(map(str, i)))
            if num >= int(n):
                ans = min(ans, num)
    return ans

def main():
    n, k = input().split()
    d_list = list(map(int, input().split()))

    like_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in d_list:
        like_list.remove(i)
    ans = float('inf')
    ans = solve(like_list, n, len(n), ans)
    if ans == float('inf'):
        ans = solve(like_list, n, len(n)+1, ans)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def check(a):
    s = str(a)
    for i in s:
        if int(i) in D: return True
    return False

n = N
while check(n):
    n += 1
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug  4 15:31:00 2018

@author: maezawa
"""

n, k = list(map(int, input().split()))
d = frozenset(list(map(str, input().split())))
ok = frozenset(list(map(str,range(10)))) - d

for i in range(n, 100000):
    if frozenset(str(i)) <= ok:
        print(i)
        break

Submission status: Accepted

Solution code:
from itertools import product as p

n,k=map(int,input().split())
e={i for i in range(10)}
d=e^set(map(int,input().split()))
f=lambda x:int("".join(map(str,x)))
g=lambda x:x>=n
h=sorted(filter(g,map(f,p(d,repeat=len(str(n))))))
if h:
  print(h[0])
else:
  h=sorted(filter(g,map(f,p(d,repeat=len(str(n))+1))))
  print(h[0])

Submission status: Accepted

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

while(True):
    for i in range(len(str(ans))):
        if str(ans)[i] in D:
            ans += 1
            break
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
N, K = input().split()
D = [int(x) for x in input().split()]
L = [str(i) for i in range(10) if i not in D]
ANS = ''
for i, n in enumerate(N):
  if n in L:
    ANS += n
  elif int(L[-1]) > int(n):
    ANS += [l for l in L if int(l) > int(n)][0]
    ANS += L[0] * (len(N) - len(ANS))
    break
  else:
    while ANS:
        c = ANS[-1]
        ANS = ANS[:-1]
        if int(L[-1]) > int(c):
          ANS += [l for l in L if int(l) > int(n)][0]
          break
    if ANS:
      ANS += L[0] * (len(N) - len(ANS))
    else:
      ANS = (L[0] if int(L[0]) else L[1]) + L[0] * len(N)
    break
print(ANS)

Submission status: Accepted

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

while any(x in D for x in str(N)): N += 1
print(N)

Submission status: Accepted

Solution code:

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


    ans = n

    Flag = False
    while True:
        for i in range(k):
            if list(str(ans)).count(d[i]) > 0:
                ans+=1
                Flag = True
                break
            if i == k -1:
                print(ans)
                exit()


if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = [Di for Di in input().split()]
for n in range(N, 1000000000):
    n = str(n)
    flag = True
    for i in range(len(str(n))):
        if n[i] in D:
            flag = False
            break
    if flag is True:
        print(n)
        exit()

Submission status: Accepted

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

flag = True
while any([i==j for i in list(map(int, list(str(n)))) for j in d]):
    n += 1
print(n)

Submission status: Accepted

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

f=1
now=n

while f>0:
    a=[]
    b=now
    while b>0:
        a.append(b%10)
        b=b//10
    f2=-1
    for c in a:
        if c in k:
            f2=1
    if f2>0:
        now+=1
    else:
        f=-1

print(now)

Submission status: Accepted

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

arr = [0,1,2,3,4,5,6,7,8,9]
r = map(int,raw_input().split())

for i in r:
	arr.remove(i)


def count_digit(num):
	count = 0
	t = num 
	while t > 0 :
		count += 1
		t /= 10
	return count

dc = count_digit(n) + 1


ans = float("inf")

def dfs(s,i):
	global ans,n,dc
	
	ret = int(s) if i > 0 else 0
	if ret >= n :
		ans = min(ans,ret)

	if i != dc :
		for j in arr :
			dfs(s + str(j),i + 1)

dfs('',0)
print ans

Submission status: Accepted

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

x = n
while True:
    flg = True
    for c in str(x):
        if c in d:
            flg = False
            break
    if flg:
        break
    x += 1
print(x)

Submission status: Accepted

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

avail = [x for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] if x not in d]

i = 0
while 1 :
    okflg = True
    for c in (str(N + i)) :
        if int(c) not in avail :
            okflg = False
            
    if okflg == True :
        print(N + i)
        break
    i += 1

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
d = [s for s in input().split()]
ans = N

while(True):
    sAns = str(ans)
    for i in range(len(sAns)):
        if sAns[i] in d:
            ans += 1
            break
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
import itertools

str_n, str_k = input().split()
n = int(str_n)
k = int(str_k)

d = set([int(di) for di in input().split()])
opt = list({0,1,2,3,4,5,6,7,8,9} - d)

def isok(num):
    if set([int(_) for _ in list(str(num))]) - set(opt) == set():
        return True
    else:
        return False

i = 0
while True:
    if isok(n + i):
        print(n + i)
        break
    i += 1

Submission status: Accepted

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

while True:
    flag = 1
    N_str = list(str(N))
    
    for s in N_str:
        if int(s) in D:
            flag = 0
            break
    
    if flag:
        print(N)
        break
    
    N += 1

Submission status: Accepted

Solution code:
import itertools, math

n, k = input().split()
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
length = len(n)
coms = itertools.product(nums, repeat=length+1)
n = int(n)
ans = float("inf")
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

coms = itertools.product(nums, repeat=length)
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

print(ans)

Submission status: Accepted

Solution code:
import itertools, math

n, k = input().split()
nums = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - {x for x in input().split()}
length = len(n)
coms = itertools.product(nums, repeat=length)
n = int(n)
ans = float("inf")
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)

coms = itertools.product(nums, repeat=length+1)
for com in coms:
    tmp = "".join(com)
    if n <= int(tmp) < ans:
        ans = int(tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
while(True):
    contain = False
    for nn in str(n):
        if int(nn) in d:
            contain = True
            n += 1
            break
    if not contain:
        break
        
print(n)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
d = set(raw_input().split())
found = False
while True:
  a = set(str(n))
  if a & d:
    n += 1
    continue
  else:
    print(n)
    break

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
d = [i for i in input().split()]

can = False
while not can:
    can = True
    n_str = str(n)
    for num in n_str:
        if num in d:
            can = False
            n += 1
            break

print(n)

Submission status: Accepted

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

while 1:
    for n_i in str(n):
        if int(n_i) in unlike:
            n += 1
            break
    else:
        print(n)
        break

Submission status: Accepted

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

while True:
    for N_i in str(N):
        if int(N_i) in D:
            N += 1
            break
    else:
        print(N)
        break

Submission status: Accepted

Solution code:
n, k = (int(char) for char in input().split())
d = [int(i) for i in input().split()]

'''
n = 10
k = 8
d = [0, 2, 3]
'''
D = [i for i in range(10)]

like_vals = [int(str(i)) for i in D if i not in d]

i = 0

n = [int(str(n)[i]) for i in range(len(str(n)))]
r = [-1] * len(n)
while i < len(n):
    if n[i] in like_vals:
        r[i] = n[i]
        i += 1
    elif n[i] < max(like_vals):
        like_bigger = [like_val for like_val in like_vals if like_val > n[i]]
        r[i] = min(like_bigger)
        for j in range(i + 1, len(n)):
            r[j] = min(like_vals)
        break
    else:
        r = [-1] * (len(n) + 1)
        if min(like_vals) != 0:
            r[0] = min(like_vals)
        else:
            r[0] = min([like_val for like_val in like_vals if like_val != 0])

        for j in range(1, len(n) + 1):
            r[j] = min(like_vals)
        break

newr = ""
for _r in r:
    newr += str(_r)
newr = int(newr)
print(newr)

Submission status: Accepted

Solution code:
from itertools import product

def generator(ls, length):
    for i in product(*(ls for i in range(length))):
        yield "".join(i)

def solve(ls, n):
    for i in generator(ls, len(n)):
        if n <= i:
            return i
    if ls[0] == "0":
        return ls[1] + "".join(ls[0] for i in range(len(n)))
    return "".join(ls[0] for i in range(len(n) + 1))


if __name__ == "__main__":
    n, k = input().split()
    ls = {chr(i) for i in range(ord("0"), ord("0") + 10)}
    ls.difference_update(set(input()))
    ls = sorted(ls)
    print(solve(ls, n))

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
d=list(input().split())
ans=10000
for i in range(n,100000):
    for j in d:
        if str(i).count(j):break
    else: 
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(str,input().split()))
flg = True
while flg:
    l = list()
    n_s = str(n)

    for i in n_s:
        if i in d:
            break
    else:
        print(n)
        flg = False
        break
    n = n +1
else:
    print(n)

Submission status: Accepted

Solution code:
def m():
    def is_included(i,d):
        s = str(i)
        for j in d:
            if str(j) in s:
                return True
        return False
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    for i in range(n, n*10):
        if not is_included(i,d):
            return i
    return 0
print(m())

Submission status: Accepted

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


for i in range(10*n+2):
  if i >= n:
    s = str(i)
    for j in range(len(s)):
      if int(s[j]) in d:
        break
    else:
      print(i)
      exit()

Submission status: Accepted

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

def solve():
  for i in range(10*n+2):
    if i >= n:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in d:
          break
      else:
        print(i)
        return 0

solve()

Submission status: Accepted

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

for ans in range(N,N*10+1):
    ch_n = str(ans)
    cnt = 0
    for c in ch_n:
        cnt += 1
        if c in D:
            break
        if cnt == len(ch_n):
            print(ans)
            exit()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, raw_input().split())
    D = raw_input().split()

    for i in range(N, N*10):
        if len(set(list(str(i))) & set(D)) == 0:
            print i
            break

main()

Submission status: Accepted

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

ans = 99999
for i in range(n, n*10):
    if set(str(i)) & d == set():
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
d = set([int(i) for i in input().split()])
while True:
    e = {int(i) for i in str(N)}
    if d & e == set({}): break
    N+=1
print(N)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
hate = [i for i in input().split()]
j = 0
k = 0
while j >= 0:
  k = 0
  for nums in hate:
    if nums in str(N):
      k += 1
    else:
      pass
  if k == 0:
    break
  else:
    N += 1

print(N)

Submission status: Accepted

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

    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

    i = 0
    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(input().split())
ans=10000
for i in range(n, n*10):
  if set(str(i)) & d == set():
    ans=i
    break
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
while True:
  if not set(str(N)) & D:
    break
  N += 1
print(N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
while True:
  if not set(str(N)) & D:
    break
  N += 1
print(N)

Submission status: Accepted

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

    price = N
    while True:
        a = False
        for x in D:
            if str(x) in str(price):
                a = True
                break
        if not a:
            break

        price += 1

    print(price)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def find_next_valid_digit(d, bad_nums):
    next_digit = d
    while True:
        valid = True
        for c in str(next_digit):
            if int(c) in bad_nums:
                valid = False
                break
        if valid:
            break
        else:
            next_digit += 1
    return next_digit

if __name__ == '__main__':
    n, k = list(map(int, input().split(' ')))
    bad_nums = list(map(int, input().split(' ')))
    n_str = str(n)
    cur_result = 0
    for i in range(len(n_str)):
        most_significant_digit = int(n_str[i])
        if most_significant_digit in bad_nums:
            basis = cur_result * 10 + most_significant_digit
            cur_result = find_next_valid_digit(basis, bad_nums)
            num_digits_to_fill = (len(n_str) - i - 1)
            num_to_fill = find_next_valid_digit(0, bad_nums)
            if num_digits_to_fill > 0:
                cur_result = (cur_result * (10**num_digits_to_fill)) + int(str(num_to_fill) * num_digits_to_fill)
            break
        else:
            cur_result = cur_result * 10 + most_significant_digit

    print(cur_result)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,10*n+1):
    judge=True
    num=list(str(i))
    num=map(int,num)
    if set(num)&set(d):
        judge=False
    if judge:
        print(i)
        exit()

Submission status: Accepted

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

    for i in range(n, 90000):
        for j in str(i):
            if int(j) in d:
                break

        else:
            print(i)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=[int(i) for i in input().split()]
a=[i for i in input().split()]
f=0
while True:
  for i in set(list(str(x))):
    if i in a:
      break
  else:
    print(x)
    break
  x+=1

Submission status: Accepted

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

while True:
	flag = True
	for i in range(0, len(str(N))):
		if str(N)[i] in D:
			flag = False
			break
	if flag:
		print N
		break
	else:
		N = N + 1

Submission status: Accepted

Solution code:
def c_iroha_obsession(N, K, D):
    for ans in range(N, 10 * N + 1):
        for digit in str(ans):  # 1桁ずつ調べる
            if int(digit) in D:  # 嫌いな数字があった
                break
        else:  # 嫌いな数字がなかった。このときのansが解
            break
    return ans
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_iroha_obsession(N, K, D))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=set(map(str,input().split()))
while True:
    flag=True
    a=list(str(n))
    for i in range(len(str(n))):
        if str(n)[i] in d:
            flag=False
            n+=1
            break
    if flag:
        break
print(n)

Submission status: Accepted

Solution code:
def check(d, x):
    x = str(x)
    for xx in x:
        if int(xx) not in d:
            return False
    return True
    
n, k = map(int, input().split())
d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(map(int, input().split()))

i = n
while 1:
    if check(d, i):
        break
    i += 1
print(i)

Submission status: Accepted

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