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:
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 10000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    if N > ans:
        for x in range(1,10):
            if x not in D:
                ans = x * 10000
                if 0 in D:
                    ans += x * 1000 + x * 100 + x * 10 + x
                break
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Submission status: Accepted

Solution code:
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 100000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Submission status: Accepted

Solution code:
N_str, K=input().split()
K=10-int(K)
N_digit=list(map(int,list(N_str)))
D=sorted(list(map(int,input().split())))
D=[d for d in range(10) if d not in D]

l_digit=[n>D[-1] for n in N_digit]

if any(l_digit):
  N_n=l_digit.index(True)
  if not any([n is not D[-1] for n in N_digit[0:N_n]]):
    out=list(str(D[1] if D[0]==0 else D[0]))
    out+=[str(D[0]) for i in range(len(N_digit))]
  else:
    flag=False
    out=[]
    for i in range(N_n):
      if not flag:
      	for j in range(K):
          if D[j]>=N_digit[i]:
            out.append(str(D[j]))
            if D[j]!=N_digit[i]:
              flag=True
              break
      else:
        out.append(str(D[0]))
    for i in range(N_n,len(N_digit)):
      out.append(str(D[0]))
else:
  out=[]
  flag=False
  for n in N_digit:
    if not flag:
      for j in range(K):
        if D[j]>=n:
          out.append(str(D[j]))
          if D[j]>n:
            flag=True
          break
    else:
      out.append(str(D[0]))
      
print(int("".join(out)))

Submission status: Accepted

Solution code:
n,K = map(int,input().split())
use = [0,1,2,3,4,5,6,7,8,9]
useless = list(map(int,input().split()))
for i in range(K):
  use.remove(useless[i])
k = 10 - K
time = [0]
def suc(time):
  now = 0
  while True:
    if now >= len(time):
      time.append(0)
      break
    elif time[now] != k-1:
      time[now] += 1
      break
    else:
      time[now] = 0
      now += 1
  return time
#print(suc([0]))
#print(suc([1,1,1,1]))
#print(suc([1,0,1,1]))
while True:
  pay = 0
  for j in range(len(time)):
    pay += use[time[j]] * 10 ** j
  if pay >= n:
    print(pay)
    break
  time = suc(time)

Submission status: Accepted

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

ans = 0
for i in range(n,100000):
    s = str(i)
    pay = True
    for j in range(len(s)):
        if s[j] in d:
            pay = False
            break
    if pay:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
import itertools
n, k = map(int, input().split())
d = list(map(int, input().split()))
ls = []
for i in range(10):
    if i not in d:
        ls.append(i)
mp = 10 ** 9
for j in range(len(str(n)), 7):
    for i in itertools.product(ls, repeat=j):
        m = int("".join(map(str, i)))
        if m >= n:
            mp = min(mp, m)
print(mp)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(str,input().split()))
a = 0 #フラグ
for i in range(n,100000):
    for j in d:
        if j in str(i): # もしも嫌いな文字dが含まれていたらこの文字iはだめ
            a = 1 #フラグをダメにする　次の値段にアップ
            break
        elif j == d[-1]: a=0 #最後までまわった⇨全て含まれない⇨フラグ０に
    if a==0:  
        print(i)
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
l = set(input().split())
ans = n
flag = True
while len(set(str(ans))&l) > 0:
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列用のリスト　インプットをブランクで区切りリスト化
k = input()
s = [int(j) for j in k.split(" ")]
valIn = 0
# Nの桁毎の分解
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

def irohacheck(n):
	global valIn
	valIn = 0
	# 分解した数値をリストにして格納
	num = digit(n)
	# num内の数字がsに含まれる場合には、valInをインクリメント
	for i in range(len(num)):
		if s.count(num[i])>0:
			valIn+=1

irohacheck(N)
while(valIn != 0):
	N += 1
	irohacheck(N)
print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
alllst = ['0','1','2','3','4','5','6','7','8','9']
dislike = [str(i) for i in input().split()]

lst = set(alllst) - set(dislike)

while True:
    st = set(str(n))
    if st.issubset(lst):
        print(n)
        break
    else:
        n += 1

Submission status: Accepted

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


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

while True:
    isOK = True
    for n in list(str(N)):
        if n in D:
            isOK = False
            break
    if isOK:
        print(N)
        sys.exit()
    N += 1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
nums = list(input().split())
for i in range(N, 100000):
  checked = True
  for char in str(i):
    if char in nums:
      checked = False
      break
  if checked:
    print(i)
    break

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = input().split()
 
def is_hate(nums, price):
  for n in nums:
    if str(n) in str(price):
      return True
  else:
    return False
 
while(is_hate(s, n)):
  n += 1
print(n)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = input().split()

def is_hate(nums, price):
  for n in nums:
    if str(n) in str(price):
      return True
  else:
    return False

while(is_hate(s, n)):
  n += 1
print(n)

Submission status: Accepted

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

for i in range(10*n - n):
    c = str(n+i)
    
    for j in a:
        if j in c:
            break
    
    else:
        ans = c
        break
        
print(ans)

Submission status: Accepted

Solution code:
#find set of numbers iroha like
tmp = raw_input("").split(' ')
n = int(tmp[0])
k = int(tmp[1])
tmp = raw_input("")
exclude_set = map(int, tmp.split(' '))

def binarySearch(arr, target):
  l = 0
  r  = len(arr) - 1
  while l <= r:
    m = (l + r)//2
    if arr[m] == target:
      return True
    elif arr[m] > target:
      r = m - 1
    elif arr[m] < target:
      l = m + 1
  return False

def check(n_digits, exclude_set):
  for i in range(0, len(n_digits)):
    if binarySearch(exclude_set, n_digits[i]) == True:
      return False
  return True
for i in range(n, 10**5):
  tmp = i
  n_digits = []
  while tmp > 0:
    n_digits.append(tmp%10)
    tmp = int(tmp/10)
  #print n_digits
  if check(n_digits, exclude_set) == True:
    print i
    break

Submission status: Accepted

Solution code:
cost, hate = map(int, input().split())
hate_num = list(map(int, input().split()))

hate_str = list(str(hate_num))
pay = cost
flag = True
while flag:
    pay_str = list(str(pay))
    for i in range(len(pay_str)):
        if set([pay_str[i]]) - set(hate_str) != set([pay_str[i]]):
            pay += 1
            flag = True
            break
        else:
            flag = False
print(pay)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
number_set = {0,1,2,3,4,5,6,7,8,9}
for i in D:
    number_set.remove(i)    

while True:
    N_str = str(N)
    list_N = list(N_str)
    list_N = [int(n) for n in list_N]
    N_set = set(list_N)

    if N_set <= number_set:
        print(N)
        break
    else:
        N+=1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, D: "List[int]"):
    tmp = N
    while True:
        i = tmp
        ng = False
        while i > 0:
            if (i % 10) in D:
                ng = True
                break
            i //= 10
        if not ng:
            print(tmp)
            return
        tmp += 1
    print(ret)
    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:
n_yen, k = map( int, input().split( ' ' ) )
unlike_numbers = set( map( int, input().split( ' ' ) ))

#like_numbers = set(range(10)) - unlike_numbers
#print( like_numbers )

n_yen_str = str( n_yen )
each_strs = [ int( each ) for each in n_yen_str ]
#print ( each_strs )

for paid_yen in range( n_yen, 10* n_yen ):
	paid_yen_str = str( paid_yen )

	each_digit_strs = set( [int( each_digit ) for each_digit in paid_yen_str ] )
	if len( unlike_numbers & each_digit_strs ) == 0 :
		print( paid_yen )
		break

Submission status: Accepted

Solution code:
n,k=[s for s in input().split()]
n=int(n)
k=int(k)
hate=list(map(int, input().split())) #hate取得
like=[]
hate.sort()
like.sort()
for i in range(10): #like取得
	if i not in hate:
		like.append(i)
pointer=0
		
for ichi in like: #1桁の場合
	if ichi>=n:
		kane=ichi
		pointer=1
		break

if pointer==0: #2桁の場合
	for ju in like:
		for ichi in like:
			if ju*10+ichi>=n:
				kane=ju*10+ichi
				pointer=1
				break
		if pointer==1:
			break


if pointer==0: #3桁の場合
	for hyaku in like:
		for ju in like:
			for ichi in like:
				if hyaku*100+ju*10+ichi>=n:
					kane=hyaku*100+ju*10+ichi
					pointer=1
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #4桁の場合
	for sen in like:
		for hyaku in like:
			for ju in like:
				for ichi in like:
					if sen*1000+hyaku*100+ju*10+ichi>=n:
						kane=sen*1000+hyaku*100+ju*10+ichi
						pointer=1
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break

if pointer==0: #5桁の場合
	for man in like:
		for sen in like:
			for hyaku in like:
				for ju in like:
					for ichi in like:
						if man*10000+sen*1000+hyaku*100+ju*10+ichi>=n:
							kane=man*10000+sen*1000+hyaku*100+ju*10+ichi
							pointer=1
							break
					if pointer==1:
						break
				if pointer==1:
					break
			if pointer==1:
				break
		if pointer==1:
			break				

if pointer==1:
	print(kane)
else:
	print("Error!!")

Submission status: Accepted

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

for i in range(N, 1000000):
    tmp = list(str(i))
    count = 0
    for j in range(len(tmp)):
        if tmp[j] not in D:
            count += 1
    if count == len(tmp):
        ans = ''.join(tmp)
        break

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
l = list(input().split())
#print(l)
l1 = [i for i in range(10) if i not in l]
#print(l1)
for i in range(n,100000):
  l2 = [False]*len(str(i))
  for j in range(len(str(i))):
    if str(i)[j] not in l:
      l2[j] = True
      a = i
    else:
      break
  if all(l2):
    print(a)
    break
  else:
    continue

Submission status: Accepted

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

num = n
while d.intersection(set(str(num))):
  num += 1
print(num)

Submission status: Accepted

Solution code:

def main():
    price, dilike_num = map(int, input().split())
    # dislike_data = list(map(int, input().split()))
    dislike_data = input().split()
    dislike_set = set(dislike_data)

    now_price = price
    while 1:
        now_price_set = set(list(str(now_price)))
        if len(now_price_set & dislike_set) == 0:
            break
        now_price += 1

    print(now_price)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#dcount = 0 #
while True:
    for n in str(N):
        if int(n) in D:
            N+=1
                # print(n,N,count) #
                #count += 1 #
            break
    else:
        print(N)
        break

Submission status: Accepted

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

def solve():
    N, K = list(map(int, input().split()))
    D = list(map(int, input().split()))

    n = N
    while True:
        k = str(n)
        ok = True
        for ki in k:
            if int(ki) in D:
                ok = False
        if ok:
            print(n)
            return
        n += 1



if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:

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

d = input().split()

while True:
    n_list = list(set(list(str(n))))

    flag = 0
    for n_data in n_list:
        if n_data in d:
            flag = 1
            break


    if flag == 0:
        print(str(n))
        exit(0)
    else:
        n += 1

Submission status: Accepted

Solution code:
import sys
def main():
    input=sys.stdin.readline
    N,K=map(int,input().split())
    D=list(map(int,input().split()))
    L=[]
    for i in range(10):
        if i not in D:
            L.append(i)
    for p in L:
        if len(str(N))==1:
            if p>=N:
                print(p)
                return
        else:
            for q in L:
                if len(str(N))==2:
                    pay=p*10+q
                    if pay>=N:
                        print(pay)
                        return
                else:
                    for r in L:
                        if len(str(N))==3:
                            pay=p*100+q*10+r
                            if pay>=N:
                                print(pay)
                                return
                        else:
                            for s in L:
                                pay=p*1000+q*100+r*10+s
                                if pay>=N:
                                    print(pay)
                                    return
    if L[0]==0:
        print(L[1]*10**len(str(N)))
    else:
        print("".join([str(L[0]) for _ in range(1+len(str(N)))]))
    return
            

if __name__=="__main__":
    main()

Submission status: Accepted

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

C = []
for k in range(10):
    if not k in D:
        C.append(k)

def num(a):
    if a!='' and (len(a) > n  or int(a)>=N):
        if int(a) >= N:
            return a
        return 114514
    d=1145141919
    for c in C:
        d =min(d, int(num(a + str(c))))
    return d

print(num(''))

Submission status: Accepted

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

n = N
while True:
    k = str(n)
    ok = True
    for ki in k:
        if int(ki) in D:
            ok = False
    if ok:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
def UnlikeNum(nums,price):
    for num in nums:
        if(str(num) in str(price)):
            return True
    
    return False

N, K = map(int,input().split())
D = list(map(int,input().split()))
while(UnlikeNum(D,N)):
    N+=1
print(N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 26 04:39:44 2019

@author: matsui
"""

N,K=map(int,input().split())
D=input().split()
D=[int(D[i]) for i in range(K)]
    
        
for n in range(N,100000):
    a=n//10000
    b=n%10000//1000
    c=n%1000//100
    d=n%100//10
    e=n%10
    
    if a+b+c+d ==0:
        if e not in D :
            print(n)
            break
    if a+b+c ==0:
        if d not in D and e not in D :
            print(n)
            break
    elif a+b ==0:
        if c not in D and d not in D and e not in D :
            print(n)
            break
    elif a ==0:
        if b not in D and c not in D and d not in D and e not in D :
            print(n)
            break
    else:
        if a not in D and b not in D and c not in D and d not in D and e not in D :
            print(n)
            break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n,k = map(int,input().split())
	d = list(map(str,input().split()))
	while True:
		s = str(n)
		flag  = True
		for i in s:
			if(i in d):
				flag = False
		if flag:
			print(n)
			sys.exit()
		else:
			n += 1


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n,k = map(int,input().split())
	d = list(map(str,input().split()))
	while True:
		s = str(n)
		flag  = True
		for i in s:
			if(i in d):
				flag = False
		if flag:
			print(n)
			sys.exit()
		else:
			n += 1


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:

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

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


now = N

while True:

    flag = True

    for d in D:

        if str(d) in str(now):
            flag = False
            break

    if flag:

        print (now)
        break

    else:

        now += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,n*(10**7)):
    f=True
    l=set(str(i))
    for k in d:
        if k in l:
            f=False
    if f:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=sorted(list(set(range(10))-set(map(int,input().split()))))
for i in range(n,100000):
    if set(map(int,str(i)))<=set(d):
        print(i)
        break

Submission status: Accepted

Solution code:
def check(num, dislike_list):
  for n in num:
    if n in dislike_list:
      return False
      break
  return True

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

while not check(str(N), dislike_num):
    N += 1

print(N)

Submission status: Accepted

Solution code:
import math

inl = input().split(' ')
length = len(inl[0])
n = int(inl[0])

hate = input().split(' ')

def checkhate(n,hate):
	n_str = str(n)
	for c in n_str:
		if c in hate:
			return False
	return True

while not checkhate(n,hate):
	n += 1

print(n)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=str(input().split())
result=n
#print(len(str(n)))
count=0
while True:
  for j in range(len(str(result))):
    if str(result)[j] in d:
      count=0
      result+=1
      #print(count,result)
      break
    else:
      count+=1
  if count==len(str(result)):
    break
print(result)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
L = input()
def func1(N):
  if len(str(N)) == 5:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L or str(N)[4] in L:
      return False
  elif len(str(N)) == 4:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L or str(N)[3] in L:
      return False
  elif len(str(N)) == 3:
    if str(N)[0] in L or str(N)[1] in L or str(N)[2] in L:
      return False
  elif len(str(N)) == 2:
    if str(N)[0] in L or str(N)[1] in L:
      return False
  elif len(str(N)) == 1:
    if str(N)[0] in L:
      return False
  else:
    return True
while func1(N) == False:
  N += 1
print(N)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
from itertools import product
def main():
    N, K = map( int, input().split())
    D = list( map( int, input().split()))
    NN = list( map( int, str(N)))
    A = [ i for i in range(10) if i not in D]
    ANS = []
    for i in range(1,6):
        for p in product(A, repeat = i):
            now = 0
            for j in range(i):
                now = now*10+p[j]
            if now >= N:
                ANS.append(now)
    print( min(ANS))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n,100000):
    s = list(map(int,list(str(i))))
    for j in s:
        if j in d:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

# numbers = [ n for n in range(10) if not n in D]

flag = 0

for i in range(Num[0],10*Num[0]+1):
    for j in str(i):
        if int(j) in D:
            flag = 1
            break

    if flag == 0:
        print(i)
        break
    else:
        flag =0

Submission status: Accepted

Solution code:
n, _ = map(int, input().split())
dislike = input().split()
while True:
  flag = True
  for it in dislike:
    if it in str(n):
      flag = False
      break
  if flag:
    print(n)
    break
  n += 1

Submission status: Accepted

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

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

i = N
while True :
    for j in str(i) :
        if not j in dec :
            break
    else :
        print(i)
        break
        
    i += 1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
A = [i for i in range(10)]
A = set(A) - set(D)
A = list(A)
A.sort()
S = str(N)
s = ''
for i in range(len(S)):
    for j in range(len(A)):
        if int(S[i]) == A[j]:
            s += str(A[j])
            break
        if int(S[i]) < A[j]:
            s += str(A[j])
            for i in range(len(S)-i-1):
                s += str(A[0])
            break
    if len(s) == len(S):
        break
            
if len(s) == len(S):
    print(s)
else:
    if A[0] == 0:
        s = str(A[1])
        for i in range(len(S)):
            s += str(A[0])
    else:
        s = str(A[0])
        for i in range(len(S)):
            s += str(A[0])
    print(s)

Submission status: Accepted

Solution code:
def main():
    n, k = list(map(int, input().split()))
    d = input().split()
    pay = n
    while True:
        ok = True
        for d_i in d:
            if d_i in str(pay):
                ok = False
                break
        if ok:
            break
        else:
            pay += 1
    print(pay)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
pay=n
d=list(map(str,input().split()))
for i in range(n,10*n):
    sp=list(str(pay))
    if any(i in sp for i in d):
        pay=i
    else:
        break
print(pay)

Submission status: Accepted

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

payment = N
while True:
  count = 0
  for i in D:
    if i in str(payment):
      break
    else: 
      count += 1
  if count == len(D):
    print(payment)
    exit()
       
  payment += 1

Submission status: Accepted

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

a = [int(i) for i in range(10) if i not in d]

ans = ""
next_d = 0
for i in range(len(str(n))-1, -1, -1):
    idx = bisect.bisect_left(a, int(str(n)[i])+next_d)
    if idx == len(a):
        next_d = 1
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        next_d = 0
        if str(n)[i] == str(a[idx]):
            ans = str(a[idx]) + ans
        else:
            ans = str(a[idx]) + "".join([str(a[0]) for j in range(len(ans))])
if next_d == 1:
    idx = bisect.bisect_left(a, 1)
    if idx == len(a):
        ans = str(a[0]) + "".join([str(a[0]) for j in range(len(ans))])
    else:
        if str(a[idx]) == "1":
            ans = str(a[idx]) + ans
        else:
            ans = str(a[idx]) + "".join([str(a[0]) for j in range(len(ans))])
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(str,input().split()))
d = set([str(x) for x in range(0,10)])-set(d)

while 1:
    can = set(list(str(n)))
    if all(x in d for x in can):
        print(n)
        break


    n+=1

Submission status: Accepted

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

for i in range(n, 100000) :
    si = str(i)
    for j in range(len(si)) :
        if si[j] in d :
            break
    else :
        print(i)
        break

Submission status: Accepted

Solution code:
# ABC042C - こだわり者いろはちゃん / Iroha's Obsession (ARC058C)
def main():
    n, k = list(map(int, input().rstrip().split()))
    D = set(map(int, input().rstrip().split()))
    ans = n
    while any(int(i) in D for i in str(ans)):
        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

N, K = map(int, input().split())
L = [v for v in input().split()]

for n in range(N, 200000):
    s = list(str(n))
    
    f = False
    for c in s:
        if c in L:
            f = True
    if f:
        continue
            
    print("".join(s))
    exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
dislike = []
for i in range(0, 10):
	dislike.append(False)
for i in range(0, K):
	dislike[D[i]] = True
while True:
	S = str(N)
	flag = True
	for i in range(0, len(S)):
		if dislike[int(S[i])]:
			flag = False
			break
	if flag:
		print(N)
		break
	N += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
dl=set(input().split())
ans=n
while True:
    for a in str(ans):
        if a in dl:
            break
    else:
        print(ans)
        break
    ans+=1

Submission status: Accepted

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

    while True:
        if len(set(n) & d)==0:
            print(n)
            break
        n = str(int(n) + 1)

if __name__=="__main__": main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Ds = set(map(int, input().split()))
nmbrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
nDs = nmbrs - Ds
payment = N
while True:
    payment_str = set(int(i) for i in str(payment))
    if payment_str.issubset(nDs) == True:
        print(payment)
        break
    else:
        payment += 1

Submission status: Accepted

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

obse_num = [0 for i in range(10)]
for i in range(K):
    obse_num[D[i]] = 1

pay_money = N

while 1:
    obse_flag = 1

    S = list(str(pay_money))
    for char in S:
        if obse_num[int(char)] == 1:
            obse_flag = 0
            break
    
    if obse_flag == 1:
        break
    
    pay_money += 1

print(pay_money)

Submission status: Accepted

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

f = []
for i in range(10):		f += [False]
for i in range(K):		f[d[i]] = True

x=N-1
l=True

while l:
	
	x+=1
	
	l=False
	b=x
	while b>0:
		if f[b%10]:
			l=True
			break
		b//=10

print(x)

Submission status: Accepted

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

while any(int(j) in D for j in str(N)):
    N+=1

print(N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def good_number(D, n):
    if n < 10:
        return n % 10 not in D
    return n % 10 not in D and good_number(D, n // 10)

N, K = input().split()
digit_num = len(N)
N = int(N)
K = int(K)
D = list(map(int, input().split()))
ub = int(str(D[0]) * (digit_num + 1))
usable = []
for i in range(10):
    if i not in D:
        usable.append(i)


if usable[0] != 0:
    ub = int(str(usable[0]) * (digit_num + 1))
else:
    ub = int(str(usable[1]) + str("0") * digit_num)
    
for i in range(N, ub + 1):
    if good_number(D, i):
        print(i)
        break