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:
# すべてを str型として読み込み、Kのみ int型に変換
N, Kstr = map(str, input().split()) # N: 元の数, K: NG数の数
K = int(Kstr)
D = list(map(str, input().split())) # D: NG数のリスト

# N = str(1000)
# K = 8
# D = ('1', '3', '4', '5', '6', '7', '8', '9')

def getMinimumOK():
# NGではない最小の数字を求める
    for i in range(0, 9):
        for j in range(1, K):
            if D[j - 1] == str(i):
                break
            else:
                return str(i)

def getFirstNG():
# Nの中の最初のNG数までの文字数を返す
# getFirstNG()を呼ぶ前にisOK(N)を呼んでいるので N の中に NG数 が必ず有る
    for i in range(0, len(N)):
        for ng in D:
            if ng == N[i]:
                return i + 1

def isOK(number):
# NG数が含まれなければ True, 含まれていれば False を返す
    strNumber = str(number)
    strlen = len(strNumber)
    for i in range(strlen):
        if strNumber[i] in D: # i桁目の数が D の中にあれば
            return False      # number に NG数 が含まれる
    return True

def makeUpperHalf(upperHalf_org):
# 引数：最初のNG数より上位の桁の数（str型）
# 戻り値：NG数を含まない上位の数（str型）
    numUpper = int(upperHalf_org)
    while True:
        numUpper += 1
        if isOK(numUpper): # NG数が無くなるまで numUpper を増やしていく
            break
    return str(numUpper)

if isOK(int(N)): # N に　NG数 が含まれていなければ
    print(N)     # N を表示して終了
else:
    minimumOK = getMinimumOK() # 最小のOK数字（文字列型）
    firstNG = getFirstNG()     # 上位から数えて最初のNG数が出てくる桁

    upperHalf = N[:firstNG] # 先頭から最初のNG数まで
    lowerHalf = N[firstNG:] # 最初のNG数の次から末尾まで
    upper = makeUpperHalf(upperHalf)
    lower = minimumOK * len(lowerHalf) # 下半分はNGでない最小の数を桁数分、並べる
    print(upper + lower)

Submission status: Accepted

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

for h in range(N,100001):
    c = True
    for e in str(h):
        if e in D:
            c = False
    if c:
        print(h)
        exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
DL = list(map(int, input().split()))
Dlist = [1,1,1,1,1,1,1,1,1,1]
for i in range(len(DL)):
  Dlist[DL[i]]=0

while True:
  f = True
  Nx = str(N)
  for i in range(len(Nx)):
    if Dlist[int(Nx[i])] == 0:
      f = False
  if f:
    print(N)
    break
  else:
    N += 1

Submission status: Accepted

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

flg = 0
flg2 = 0
while flg == 0:
	for i in range(len(str(n))):
		flg2 = 0
		if int(str(n)[i]) in d:
			flg2 = 1
			n += 1
			break
	if flg2 == 0:
		flg = 1
print (n)

Submission status: Accepted

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

ans = n
while True:
    if any( [x in D for x in list(map(int,str(ans)))] ):
        ans += 1
    else:
        print(ans)
        break

Submission status: Accepted

Solution code:
min = list(map(int,input().split()))[0]
min = int(min)
l = list(map(int,input().split()))
while True:
  temp = min
  flag = True
  for i in range(len(str(min))):
    temp_ = temp % 10
    if temp_ in l:
      min += 1
      flag = False
      break
    else:
      temp //= 10
  if i == len(str(min))-1 and flag:
    break
print(min)

Submission status: Accepted

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

def check(n):
    while n > 0:
        if n % 10 in Data:
            return False
        n //= 10
    return True

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

print(N)

Submission status: Accepted

Solution code:
cnt=[0,1,2,3,4,5,6,7,8,9]
n,k=map(int,input().split())
d=list(map(int,input().split()))
tmp=[]
for i in range(k):
    cnt.remove(d[i])

def digit(x):
    xt=str(x)
    for i in range(len(xt)):
        if not int(xt[i]) in cnt:
            return  False
    return  True
t=n
while t>=n:
    if digit(t):
        print(t)
        exit()
    else:
        t+=1

Submission status: Accepted

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

for i in range(total,total*10+2):
  for d in ds:
    if d in list(str(i)):
      break
  else:
    print(i)
    exit(0)

Submission status: Accepted

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

ans = total
while True:
  flag = False
  for d in ds:
    if d in list(str(ans)):
      flag = True
  if flag:
    ans += 1
  else:
    print(ans)
    exit(0)

Submission status: Accepted

Solution code:
def examC():
    import bisect
    N, K = LI()
    D = list(map(str,input().split()))
    ansC = []
    for i in range(100001):
        cur = str(i)
        k = 1
        for s in cur:
            if s in D:
                k = 0
                break
        if k==1:
            ansC.append(i)
#    print(ansC)
    k = bisect.bisect_left(ansC, N)
    ans = ansC[k]
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
D=list(map(int,input().split()))

temp=[]
for i in range(10):
    if D.count(i)==0:
        temp.append(i)
D=temp[:]
preK=0
K=10-K

opt=D[:]
ans=10**18

for item in opt:
    if item>=N:
        ans=min(ans,item)

for t in range(5):
    for d in D:
        for i in range(preK,K):
            if opt[i]==0:
                pass
            else:
                num=int(str(opt[i])+str(d))
                if num>=N:
                    ans=min(ans,num)
                else:
                    opt.append(num)
    preK,K=K,len(opt)        
print(ans)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

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

for i in range(N,N*10+1):
    if not D&set(str(i)):
        break

print(i)

Submission status: Accepted

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

for i in range(N,10*N+1):
    I=[int(j) for j in list(str(i))]
    cnt=0
    
    for j in I:
        if j not in L:
            break
        else:
            cnt+=1
    if cnt==len(I):
        ans=i
        break

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
x = n
d = set(map(str,input().split()))
can_use = {str(i) for i in range(10)} ^ d
s_can_use = sorted(list(can_use))
'''
for i in range(9): 
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        if s_can_use[0] == 0:
'''
for i in range(10**6):
    if set(list(str(x))) | can_use == can_use:
        print(n)
        break
    else:
        n += 1
        x = n
#print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = set(input().split())
use = set(map(str, range(10)))
use -= D

for num in range(n, 100*n):
    if use >= set(list(str(num))):
        print(num)
        exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
D = set(input().split())
use = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
use -= D
use = list(use)
l = len(str(n))

ans = use.copy()
prev = use.copy()
digit = 0
while digit <= l:
    temp = []
    for x in prev:
        for v in use:
            temp.append(x+v)
    ans += temp
    prev = temp
    digit += 1

ans = list(map(int, ans))
ans.sort()

for num in ans:
    if num >= n:
        print(num)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    l = [int(x) for x in str(N)]
    for e in l:
        if e in D:
            N += 1
            break
    else:
        break
print(N)

Submission status: Accepted

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

def checkIfOk(num):
  while True:
    if num%10 in d:
      return False
    else:
      num=num//10
    if num==0:
      return True

while True:
  if checkIfOk(n):
    print(n)
    break
  n+=1

Submission status: Accepted

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

while True:
  ans += 1
  str_ans = list(map(int, str(ans)))
  ans_len = len(str(ans))
  ans_check = 0
  for i in range(ans_len):
    if str_ans[i] not in D:
      ans_check += 1
  if ans_len == ans_check:
    print(ans)
    break

Submission status: Accepted

Solution code:
n,k = [int(i) for i in input().split()]
all_num = {'0','1','2','3','4','5','6','7','8','9'}
l = all_num - {i for i in input().split()}

for i in range(n,n*20):
    if not set(str(i)) - l:
        print(i)
        break

Submission status: Accepted

Solution code:
import itertools
N,K=map(int,input().split())
D=set(list(map(str,input().split())))
U=list({'0','1','2','3','4','5','6','7','8','9'}^D)
U.sort()

PRD1 = list(itertools.product(U, repeat=len(str(N))))
PRD2 = list(itertools.product(U, repeat=len(str(N))+1))

import sys
for i in range(len(PRD1)):
    T=int(''.join(PRD1[i]))
    if T>=N:
        print(T)
        sys.exit()

for i in PRD2:
    T=int(''.join(i))
    if T>=N:
        print(T)
        sys.exit()

Submission status: Accepted

Solution code:
# coding: utf-8
N, K = map(int, input().split())
D = list(map(str, input().split()))
for tmp in range(N, 10*N+1):
    tmp_l = list(str(tmp))
    cnt = 0
    for t in tmp_l:
        if t in D:
            cnt += 1
    if cnt == 0 and int(tmp) >= N:
        print(tmp)
        exit()

Submission status: Accepted

Solution code:
ns,k = input().split()
nlist = set(input().split())
nslist = set(list(ns))
while nslist & nlist:
    ns = int(ns)+1
    ns = str(ns)
    nslist = set(list(ns))
print(ns)

Submission status: Accepted

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

ans = 0

for j in range(N,10*N+1):
  f = True
  for k in D:
    if str(k) in str(j):
      f = False
      break
  if f:
    ans = j
    break
    
print(ans)

Submission status: Accepted

Solution code:
line=input().split()
N=int(line[0])
K=int(line[1])
D=input().rstrip().split()

for i in range(N,10*N+1):
 s=str(i)
 flag=True
 for x in D:
  if x in s:
   flag=False
   break

 if flag:
  print(s)
  break
 else:
  continue

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    Dk = lines[1].split()
    for i in range(N, 10 * N):
        for D in Dk:
            if D in str(i):
                break
        else:
            print(i)
            break
    return


main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=input().split()
r=N
while True:
    if not any([c in D for c in str(r)]):
        break
    r+=1
print(r)

Submission status: Accepted

Solution code:
#042c slow
N,K = map(int, input().split())
D_set = set([int(e) for e in input().split()])

INF = 9999999999

OK_D = {0,1,2,3,4,5,6,7,8,9} - D_set

OK_D_list = list(OK_D)
OK_D_list.sort

ans = []
pay = 0

def dfs(pos,pay):
    #print("#####################")
    #print(pay)
    
    #停止条件
    #深さに限らず，任意の停止条件を書く
    if pos >= 5 or pay>=N:
        #print("%%%%%%%%%%%%%%%%")
        if pay>=N:
        #支払い出来る
            ans.append(pay)
            return pay
        else:
            return INF
        
    # pos (bamboo_number)を進めながら（末端に進みながら）分岐処理
    # 末端まで到達した時それぞれの分岐から値が返される
    for number in OK_D_list:
        #print(number)
        dfs(pos+1 ,pay*10 + number) 
        
    #それぞれの分岐からの戻り値の処理を行う関数

dfs(0,0)
#print("###############")
#print(ans)
print(min(ans))

Submission status: Accepted

Solution code:
import itertools
N,K = map(int,input().split())
D = list(map(int,input().split()))
A = []
for i in range(10):
    if i not in D:
        A.append(i)
cmin = 100000
k = len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt = 0
        for j in range(i):
            cnt += x[j]*10**(i-1-j)
        if cnt>=N:
            cmin = min(cmin,cnt)
print(cmin)

Submission status: Accepted

Solution code:
import string
import sys

N,K=[int(i) for i in input().split()]
D=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in D]

def check(use,x):
    for i in str(x):
        if(int(i) not in use):
            return False
    return x

i=N-1
while True:
    i+=1
    x=check(use,i)
    if(x!=False):
        print(x)
        sys.exit()

Submission status: Accepted

Solution code:
"""
author : dokueki
1000 8
1 3 4 5 6 7 8 9
"""
def check(x,arr):
    c=0
    s = [int(i) for i in str(x)]
    for i in s:
        if i in arr:
            c+=1
    if c==len(s):
        return True
    return False


n, k = map(int, input().split())
a = list(map(int, input().split()))
use,f = [],0
for i in range(0, 10):
    if i not in a:
        use.append(i)
#print(use)
paid = [int(i) for i in str(n)]
for i in paid:
    if i in use:
        f+=1
if f==len(paid):
    print(n)
else:
    while True:
        n+=1
        if check(n,use)==True:
            print(n)
            break

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
D = list(map(int,input().split()))
a = 10 
b = 10
c = 10
d = 10
e = 10
ans = 100000
for i in range(N,100000):
    if i >= 10000:
        a = i//10000
    if i >= 1000:
        b = (i//1000)%10
    if i >= 100:
        c = (i//100)%10
    if i >= 10:
        d = (i//10)%10
    e = i%10
    S = D.count(a) + D.count(b) + D.count(c) + D.count(d) + D.count(e)
    if S == 0:
        if ans > i:
            ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, K: int, D: "List[int]"):    
    while True:
        for d in D:
            strn=str(N)
            if str(d) in strn:
                break
        else:
            print(N)
            return 
        N+=1

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(K)]  # type: "List[int]"
    solve(N, K, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

#金額と個数の入力
sum,num = map(int,input().split())
#嫌いな数字の入力
dis = list(map(int,input().split()))

pay = sum
while True:
  flag = 0;
  str_pay = str(pay)
  for i in str_pay:
    if int(i) in dis:
      flag = 1
      break
  if flag == 0:
    break
  else:
    pay = pay + 1
print(pay)

Submission status: Accepted

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

while 1:
    if all(dd not in str(n) for dd in d):
        print(n)
        break
    n = n+1

Submission status: Accepted

Solution code:
n, k = list(map(int,(input().split(' '))))
d = set(list(map(int,(input().split(' ')))))
l = set(list(range(0,10)))

like = l -d 
#print(like)
#print(list(map(int,(str(10001)))))

for i in range(n,100001):
  #print(i)
  if like >= set(list(map(int,(str(i))))):
  #  print(list(like),list(map(int,(str(i)))))
    #print(i)
    break

print(i)    
#print(like >= set(list(map(int,(str(10000))))))

Submission status: Accepted

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

for i in range(N,10*N+1):
  s=str(i)
  flag=True
  for x in D:
    if x in s:
      flag=False
      break
  if flag:
    print(s)
    break
  else:
    continue

Submission status: Accepted

Solution code:
#こだわりイロハちゃん
n,k=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[]
for i in range(k):
    uselist.append(str(lists[i]))
flag=True
flag2=True
ans=str(n)
while flag2:
    for i in range(len(ans)):
        if ans[i] in uselist:

            flag=False
            break
        else:

            pass
    if flag:
        flag2=False
    else:
        flag=True
        ans=int(ans)
        ans+=1
        ans=str(ans)
print(ans)

Submission status: Accepted

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

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

for a in use_list:
    if int(a) >= n:
        print(int(a))
        exit()

for a in use_list:
    for b in use_list:
        if int(a+b) >= n:
            print(int(a+b))
            exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            if int(a+b+c) >= n:
                print(int(a+b+c))
                exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            for d in use_list:
                if int(a+b+c+d) >= n:
                    print(int(a+b+c+d))
                    exit()

for a in use_list:
    for b in use_list:
        for c in use_list:
            for d in use_list:
                for e in use_list:
                    if int(a+b+c+d+e) >= n:
                        print(int(a+b+c+d+e))
                        exit()

Submission status: Accepted

Solution code:
tg = int(input().split(' ')[0])
target_int = set(list( str(tg) ))
deny_int= set(input().split(' '))

while target_int - deny_int != target_int:
  tg= tg+1
  target_int = set(list(str(tg)))

print(tg)

Submission status: Accepted

Solution code:
import sys
import bisect
all_flg = False
n, k = [int(i) for i in sys.stdin.readline().split()]
d_ls = [int(i) for i in sys.stdin.readline().split()]
candidate = [i for i in range(10) if i not in d_ls]
set_candidate = set(candidate)
len_cand = len(candidate)
last_ans = n
while True:
    ans = list(str(last_ans))
    flg = False
    flg_ls = [0 for i in range(len(str(n)))]
    for i, s in enumerate(str(last_ans)):
        s = int(s)
        res = bisect.bisect_left(candidate, s)
        if flg:
            ans[i] = str(candidate[0])
        else:
            if res >= len_cand:
                flg_ls[i] = 1
            ans[i] = str(candidate[res if res < len_cand else 0])
        if s not in set_candidate:
            flg = True
    ans = int("".join(ans))
    hoge = int("".join([str(i) for i in flg_ls]) + "0")
    ans += hoge
    if ans == last_ans:
        break
    last_ans = ans
print(ans)

Submission status: Accepted

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


def isOk(n, D):
    while n > 0:
        if n % 10 in D:
            return False
        n //= 10
    return True


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    ans = 0
    for i in range(N, 10**5):
        if isOk(i, D):
            print(i)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N, 100001):
    tmp = i
    while tmp > 0 and tmp % 10 not in D:
        tmp = tmp // 10
    if tmp == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dis = input().split()
m = n
while True:
    m = str(m)
    for d in dis:
        if d in m:
            break
    else:
        print(m)
        exit()

    m = int(m) + 1

Submission status: Accepted

Solution code:
price, size = map(int, input().split())
dislikes = list(map(int, input().split()))
likes = list(set(range(10)) - set(dislikes))
digits = [int(digit) for digit in str(price)]
r_digits = list(reversed(digits))
res = []
for i in range(len(r_digits)):
    if r_digits[i] in likes:
        res.append(r_digits[i])
    elif max(likes) > r_digits[i]:
        res = [min(likes) for i in range(i)] + [min(x for x in likes if x > r_digits[i])]
    else:
        res = [min(likes) for i in range(i+1)]
        if i == len(r_digits)-1:
            res.append(min(x for x in likes if x > 0))
            
        else:
            r_digits[i+1] += 1

ans = "".join([str(num) for num in list(reversed(res))])
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
d = list(map(int, input().split()))
a = []
for i in range(10):
    if d.count(i) == 0:
        a.append(i)
ans = []
def dfs(s):
    if int(s) >= N or len(s) > 6:
        return s
    for i in a:
        S = dfs(s + str(i))
        if int(S) >= N:
            ans.append(int(S))
    return s
    
dfs('0')
print(min(ans))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
nums =set(input().split())
i = n
while True:
    i = str(i)
    for num in nums:
        if num in i:
            break
    else:
        print(i)
        exit()
    
    i =int(i)+1

Submission status: Accepted

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

t = N
while 1:
    s = str(t)
    flg = True
    for i in range(len(s)):
        if s[i] in D:
            flg = False
    if flg:
        res = t
        break
    t += 1
print(res)

Submission status: Accepted

Solution code:
val, size = map(int, input().split())
disabledList = [int(x) for x in input().split()] # number
enableList = list(set(range(10)) - set(disabledList)) # number
resultList = [] # str, must reverse
isTenOver = False
for char in reversed(list(str(val))):
  targetInt = int(char)
  if isTenOver:
    targetInt += 1
  if targetInt in enableList:
    isTenOver = False
    resultList.append(str(targetInt))
    continue
  resultList = [str(min(enableList))] * len(resultList)
  if targetInt > max(enableList):
    isTenOver = True
    resultList.append(str(min(enableList)))
  else:
    isTenOver = False
    minNum = min(filter(lambda x:x > targetInt, enableList))
    resultList.append(str(minNum))

if isTenOver:
  minNum = min(filter(lambda x:x > 0, enableList))
  resultList.append(str(minNum))
print(''.join(reversed(resultList)))

Submission status: Accepted

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

for i in range(N,N*10):
  flag = True
  for d in str(i):
    if d in D:
      flag = False
      break
  if flag:
    print(i)
    exit()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = set(list(map(int,input().split())))
for i in range(N,10*N):
  ans = []
  ans += str(i)
  sA =set(map(int,ans))
  if sA&D == set():
    break

print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p, _ = [int(x) for x in input().split(' ')]
v = set([str(x) for x in range(10)]) - set(input().split(' '))

for x in range(p, 100000):
  if all([s in v for s in str(x)]):
    print(x)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - こだわり者いろはちゃん / Iroha's Obsession

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

set_str_N = set(str(N))

while len(set_str_N & D) > 0:
    N = N + 1
    set_str_N = set(str(N))
    
print(N)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
all_num = [i for i in range(10)]
not_d = list(set(all_num) - set(d))
not_d_str = [str(i) for i in not_d]
#print(set(not_d_str))
ans = []
for i in range(n, 10 * n):
    if set(list(str(i))).issubset(set(not_d_str)):
        print(i)
        exit()
    #print("f", i)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
all_num = [i for i in range(10)]
not_d = list(set(all_num) - set(d))
not_d_str = [str(i) for i in not_d]
ans = []
for i in range(n, 10 * n):
    if set(list(str(i))).issubset(set(not_d_str)) and i >= n:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
nd = list()
for i in range(10):
    if i not in d:
        nd.append(i)
a = n

for i in range(10*n):
    if set([int(m) for m in list(str(a+i))]) == set(list(set([int(m) for m in list(str(a+i))]) & set(nd))):
        print(a+i)
        break

Submission status: Accepted

Solution code:

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

    
l=input().split()
def check(s): 
    for i in s: 
        if i in l: 
            return 0 
    return 1 
for x in range(n,10**9): 
    if check(str(x)):
        print(x)
        exit()

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for i in list(map(int, input().rstrip('\n').split())):
        d[i]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for j in range(len(s)):
            if int(s[j]) in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

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

N = n
flug = False
while(1):
    n_st = list(str(n))
    n_st = list(map(int,n_st))

    for i in range(len(n_st)):
        if not(n_st[i] in d):
            break
        if i == len(n_st)-1:
            flug = True

    if(flug):
        break
    n+=1

print(n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
price, count = list(map(int, input().split()))
hate_numbers = list(map(int, input().split()))

def is_ok(hates, price):
  for h in hates:
    if str(h) in list(str(price)):
      return False
  return True

for p in range(1, 100000):
  if is_ok(hate_numbers, p) is False:
    continue
  if p >= price:
    print(p)
    exit(0)

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    d = set(list(map(str, input().split())))
    checker = 1
    while checker:
        if set(list(str(n))).isdisjoint(d):
            print(n)
            checker = 0
        else:
            n += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

N_keta=list(map(int,str(N)))

for n in range(100000):
  count=0
  for k in range(len(N_keta)):
    if N_keta[k] in li:
      count=1
      break
    
  if count==0:
    print(N)
    break
  else:
    N+=1
    N_keta=list(map(int,str(N)))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(map(str, input().split()))
num = {str(i) for i in range(10)}
available = num - d
ans = 0
for i in range(n, 10**5):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

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

l = set(input().split())

i = N
while(True):
  if(len(l & set(str(i))) == 0):
    print(i)
    break
  i += 1

Submission status: Accepted

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

for i in range(n, 1000000):
  r = [x for x in list(str(i))]
  if list(set(r)&set(d))==[]:
    print(i)
    break

Submission status: Accepted

Solution code:
# ABC042 C Iroha's Obsession
N,K = map(int,input().split())
D = tuple(map(str,input().split()))

for i in range(N,1000000):
    S = str(i)
    is_iroha = True
    for s in S:
        if s in D:
            is_iroha = False
            break
    if is_iroha:
        print(S)
        exit()

Submission status: Accepted

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


for i in range(N,100001): 
    tmp = i 
    while tmp > 0 and tmp % 10 not in D:
        tmp = tmp // 10 
    if tmp == 0:
        print(i)
        break

Submission status: Accepted

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

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