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:
N, K = map(str, input().split())
D = map(str, input().split())

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)


out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
        flag = 2
  elif flag == 1:
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
      flag = 2
  elif flag == 2:
    res_list.append(out[0])
        
if flag == 1:
  res_list.append(out[0])  
res = ''
for i in range(len(res_list)):
  res += res_list[i]
print(res)        
    
          
"""
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
if flag == 1:
  res_list.append(out[0])
  
res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)
"""

Submission status: Accepted

Solution code:
def chk(n,arr):
	while n>0:
		if n%10 in arr:
			return True
		n//=10
	return False


n,k = map(int,input().split())
arr = set(list(map(int,input().split())))
while chk(n,arr):
	n+=1
print(n)

Submission status: Accepted

Solution code:
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def contains_digit(number, digits):
    while number != 0:
        if number%10 in digits:
            return True
        number //= 10
    return False


def solve():
    N, K = read_ints()
    digits = set(read_ints())
    while contains_digit(N, digits):
        N += 1
    return N


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

Submission status: Accepted

Solution code:
from collections import defaultdict

n, k = map(int, input().split())
d = list(map(int, input().split()))
nums = defaultdict(int)
for i in range(len(d)):
    nums[d[i]] += 1

def judge(n, nums):
    n = str(n)
    for i in range(len(n)):
        if nums[int(n[i])] == 1:
            return False
        
    return True

while 1:
    if judge(n, nums) == True:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
dis=[i for i in input().split()]
for i in range(n,10*n):
  if set(dis).isdisjoint(str(i)):
    print(i)
    break

Submission status: Accepted

Solution code:
def check(x,d):
    s=str(x)
    flag=True 
    for i in range(len(s)):
        if int(s[i]) not in d:
            flag=False 
    return flag
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
d=[]
for i in range(10):
    if i not in a:
        d.append(i)
l=len(str(n))
final=10**l 
flag=False
#print(d)
for i in range(n,final):
    #print("HI")
    if check(i,d):
        flag=True
        print(i)
        break 
if not flag:
    if d[0]==0:
        print(str(d[1])+"0"*(l))
    else:
        print(str(d[0])*(l+1))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = set(map(int,input().split()))
for i in range(n,1000001):
  x = str(i)
  for j in x:
    if int(j) in a:
      break
  else:
    print(i)
    break

Submission status: Accepted

Solution code:
def abc042_c():
  n, _ = map(int, input().split())
  D = list(map(int, input().split()))
  for i in range(n, 10**5):
    like = True
    for s in str(i):
      if int(s) in D:
        like = False
        break
    if like:
      print(i)
      return

abc042_c()

Submission status: Accepted

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

for i in range(N, 10**6):
    if N <= i and len(set(str(i)) & D) == 0:
        print(i)
        exit()

Submission status: Accepted

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

usable = sorted( list( {str(i) for i in range(10)} - hate))

l = len(str(n))

def check(l):
    num = []
    if l == 1:
        for i in usable:
            num.append(int(i))
    elif l == 2:
        for ii in usable:
            for i in usable:
                num.append(int( ii + i))
    elif l == 3:
        for iii in usable:
            for ii in usable:
                for i in usable:
                    num.append(int( iii + ii + i))
    elif l == 4:
        for iv in usable:
            for iii in usable:
                for ii in usable:
                    for i in usable:
                        num.append(int( iv + iii + ii + i))
    else:
        for v in usable:
            for iv in usable:
                for iii in usable:
                    for ii in usable:
                        for i in usable:
                            num.append(int( str(v) + str(iv) + str(iii) + str(ii) + str(i)))
    return num

truf = False
num = check(l)
for i in num:
    if n <= i:
        print(i)
        truf = True
        break
if not truf:
    num = check(l+1)
    for i in num:
        if n <= i:
            print(i)
            break

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
d = na()
s = str(n)

ans = []
res1 = 0
res2 = 0

while res1 < n:
    if res1 == 0:
        for i in range(1, 10):
            if i not in d:
                res1 *= 10
                res1 += i
                break
    else:
        for i in range(10):
            if i not in d:
                res1 *= 10
                res1 += i
                break

j = 0
while res2 < n:
    ok = False
    for i in range(10):
        if i not in d and res2 * 10 + i >= int(s[:j + 1]):
            res2 *= 10
            res2 += i
            ok = True
            break
    if not ok:
        res2 = inf
        break
    j += 1

print(min(res1, res2))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 制約が小さいので愚直に全探索すればいい気もする
N, K = read_ints()
D = set(input())
# print(D)
for n in range(N, N + 10 ** 6):
    n_str = str(n)
    for c in n_str:
        if c in D:
            break
    else:
        print(n)
        exit()
# print(n)

Submission status: Accepted

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

for i in range(n,100001):
     for x in d:
         if str(x) in str(i):
             break
     else:
         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,n*10+1):
     for x in d:
         if str(x) in str(i):
             break
     else:
         print(i)
         break

Submission status: Accepted

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

ans, i, OK = str(N), 0, False
while not OK:
    OK = True
    digit = len(ans)
    for i in range(digit):
        if ans[i] in D:
            k = digit - i - 1
            ans = str((int(ans)//(10**k) + 1)*10**k)
            OK = False
            break
print(ans)

Submission status: Accepted

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

n = N
while True:
    d = set(list(str(n)))
    check = D & d
    if len(check) == 0:
        break
    n += 1

print(n)

Submission status: Accepted

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

while True:
    for i in str(n):
        flag=True
        if int(i) in d:
            flag=False 
            break
    if flag:
        break
    else:
        n+=1

print(n)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
l = list(map(str,input().split()))
for i in range(n,10**7):
  a = [j for j in str(i)]
  if set(a).isdisjoint(set(l)):
    print(i)
    exit()

Submission status: Accepted

Solution code:
a,n=map(int,input().split())
b=input()
c=[]
for i in range(n):
  c.append(int(b[2*i]))
flag="F"
while flag=="F":
  k=a
  fflag="T"
  while k>=1:
    l=int(k%10)
    for i in range(n):
      if c[i]==l:
        fflag="F"
        break
    k=int(k/10)
    if fflag=="F":
      break
  if fflag=="T":
    flag="T"
  else:
    a+=1
print(a)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    while True:
        feasible = True
        for n in str(N):
            if int(n) in D:
                feasible = False
                break
        if feasible:
            break
        else:
            N += 1

    print(N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n,k = map(int,input().split())
d = list(map(int,input().split()))
 
for i in range(100000):
    s = str(i)
    n2 = len(s)
    fl = 0
    for j in range(len(s)):
        for k in d:
            if s[j] == str(k):
                fl = 1
                
    if fl == 0:
        if i >= n:
            print(i)
            break

Submission status: Accepted

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

p=N

def check(p,D):
  st=str(p)
  for char in st:
    if char in D:
      return False
  else:
    return True
  
while check(p,D)==False:
  p += 1
  
print(p)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
list_D = list(map(str, input().split()))
num = n
ans = -1

while True:
    S = list(str(num))
    cnt = 0
    for s in S:
        if s  in list_D:
           cnt += 1
    if cnt == 0:
        ans = num
        break
    num += 1

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
list_D = set(map(str, input().split()))
num = n
ans = -1

while True:
    S = set(list(str(num)))
    cnt = 0
    for s in S:
        if s  in list_D:
           cnt += 1
    if cnt == 0:
        ans = num
        break
    num += 1

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
D = set(input().split())
for i in range(N, 100000):
    flag = 1
    for char in str(i):
        if char in D:
            flag = 0
            break
    if flag:
        print(i)
        break

Submission status: Accepted

Solution code:
def main(data: list):
    [price, numbers] = data
    numbers_set = set(numbers)
    while True:
        unique_price_numbers = set(map(int, list(str(price))))
        common_numbers = numbers_set.intersection(unique_price_numbers)
        if len(common_numbers) == 0:
            print(price)
            break
        price += 1


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

Submission status: Accepted

Solution code:
#coding: utf-8

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

while 1:
    flg = 1
    for d in D:
        if d in str(N): flg = 0
    if flg:
        print(N)
        break
    N += 1

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):
    for x in d:
        if str(x) in str(i):
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
def main():
  N, K = (int(_) for _ in input().split())
  D = set(input().split())
  ret = 10 ** 10
  for a in range(10):
    for b in range(10):
      for c in range(10):
        for d in range(10):
          for e in range(10):
            cc = str(int(str(a) + str(b) + str(c) + str(d) + str(e)))
            for s in cc:
              if s in D:
                break
            else:
              if int(cc) >= N:
                ret = min(ret, int(cc))
  print(ret)
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

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

for i in range(n,10*n):
    flag=0
    sn=str(i)
    for j in sn:
        if j in d:
            flag=1
    if flag==0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
from collections import deque
N,K=map(int,input().split())
l=list(map(int,input().split()))
num=[1]*10
nums=[]
d=deque()
ans=[]
for i in range(len(l)):
    num[l[i]]=0
for i in range(10):
    if num[i]==1:
        nums.append(i)
        d.append(i)
#print(nums)
for i in range(10000):
    v=d.popleft()
    ans.append(v)
    for j in nums:
        if v!=0:
            d.append(v*10+j)
    #print(ans)
    #print(d)
    #input()
#print(len(ans),len(set(ans)),ans[len(ans)-1])
for i in range(len(ans)):
    if ans[i]>=N:
        print(ans[i])
        break

Submission status: Accepted

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

Alist_str = [str(n) for n in Alist]

M=N
while True:
    Mlist_str = list(str(M))
    double = set(Alist_str) & set(Mlist_str)
    if len(double) == 0:
        print(M)
        break
    else:
        M = M +1

Submission status: Accepted

Solution code:
amount, num = map(int, input().split())

hate_num_list = list(map(str, input().split()))

while(True):

    check = 0

    for digit in str(amount):

        if digit in hate_num_list:
            check += 1

    if check == 0:
        print(amount)
        break

    else:
        amount += 1

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
for i in range(100001):
  nn = n+i
  cnt = 0
  for j in d:
    if str(j) in str(nn):
      break
    else:
      cnt += 1
  if cnt == len(d):
    print(nn)
    break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())                            
array = list(map(int, input().split()))
 
def jadgesuruo():
    for i in range(k):
        if str(n).find(str(array[i])) >= 0:
            return False
            break
    return True
 
while True:
    if jadgesuruo():
        print(n)
        break
    else:
        n = n + 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())                            
array = list(map(int, input().split()))
 
def jadgesuruo():
    for i in range(k):
        if str(n).find(str(array[i])) >= 0:
            return False
            break
    return True
 
for i in range(10**5):
    if jadgesuruo():
        print(n)
        break
    else:
        n = n + 1

Submission status: Accepted

Solution code:
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,k=INPUT()
A=INPUT()
accepted=[]
for i in range(10):
    if i not in A:
        accepted.append(i)
L=len(accepted)
#print(accepted)
ans=n
i=0
p=len(str(ans))
while(i<p):
    if int(str(ans)[i]) in accepted:
        #print(str(ans))
        i+=1
    else:
        ans+=1
        i=0
    p=len(str(ans))
print(ans)

Submission status: Accepted

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


for i in range(100001):
    if i >= int(N):
        ans=str(i)
        num=0
        for j in range(len(ans)):
            if int(ans[j]) not in listA:
                num += 1

            if num == len(ans):
                print(i)
                exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
flag = True
ans = N
while flag:
    ans_nums = []
    x = ans
    while x>=1:
        ans_nums.append(x%10)
        x = (int)(x/10)
    #print(ans_nums)
    a = list(set(ans_nums) & set(D))
    #print(a)
    if len(a) == 0:
        flag = False
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,k,*d=map(int,open(0).read().split())
c=0
for i in range(n*10):
  if n<=i:
    for j in str(i):
      if not int(j) in d:
        c+=1
      if c==len(str(i)):
        print(i)
        exit()
    c=0

Submission status: Accepted

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

for nn in range(n,10*n+1):
    if len(set(str(nn)) & d)==0:
        print(nn)
        break

Submission status: Accepted

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

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

L.sort()

i = N
while True:
    if set(list(str((i)))) <= set(L):
        print(i)
        break
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
D = list(map(int, input().split()))
dt = [True] * 10
for d in D:
    dt[d] = False

def check(x):
    while x:
        if not dt[x%10]:
            return False
        x //= 10
    return True

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

Submission status: Accepted

Solution code:
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

if n < 10:
    for i in ele:
        if i >= n:
            print(i)
            exit()

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y >= n:
            print(y)
            exit()
        else:
            que.append(y)

Submission status: Accepted

Solution code:
from collections import deque
N,K=map(int,input().split())
a=list(map(int,input().split()))
A=deque([str(i) for i in range(10) if i not in a])
B=[str(i) for i in range(10) if i not in a]
while True:
  s=A.popleft()
  if int(s)>=N:
    print(s)
    exit()
  A.extend([s+i for i in B])

Submission status: Accepted

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

ans=N

for price in range(N,10**5+1):
    s=str(price)
    flag=True
    for i in range(len(s)):
        if int(s[i]) in D:
            flag=False
    if flag:
        ans=price
        break

print(ans)

Submission status: Accepted

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

i = N
while True:
  flg = True
  for j in str(i):
    if int(j) in D:
      flg = False
      break

  if flg == True:
    print(i)
    exit()

  i += 1

Submission status: Accepted

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

flag = False

for i in range(N,100000):
    N = i
    while i > 0:
        flag = True
        if i%10 in D:
            flag = False
            break
        else:
            i //=10

    if flag == True:
        print(N)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b = map(int, input('').split(' '))
c = input('').split(' ')
for i in range(a, 1000000):
	for j in range(len(str(i))):
		if str(i)[j] in c:
			break
	else:
		print(i)
		break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
d ^= {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}

while True:
    if d >= set(map(int, list(str(n)))):
        print(n)
        break
    n += 1

Submission status: Accepted

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

# 10Nが最大という全探索

for ans in range(N, 10 * N + 1):
    s = str(ans)
    flag = True
    for ch in s:
        if int(ch) in setD:
            flag = False
            break
    if flag:
        print(ans)
        exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

from collections import deque

N, K = mi()
D = list(map(str, sys.stdin.readline().split()))

for num in range(N, N*10+1):
    flag = 1
    s = str(num)
    for i in range(K):
        if s.count(D[i]):
            flag = 0
            break
    if flag:
        print(num)
        exit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    que = deque(r[1:])
    #que = r[:][1:]
else:
    que = deque(r)
    #que = r[:]

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    i += 1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
#from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    #que = deque(r[1:])
    que = r[:][1:]
else:
    #que = deque(r)
    que = r[:]

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    #if que[-1] >= 10**6:
        #break
    i += 1

#ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
#print(que[ind])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    que = deque(r[1:])
else:
    que = deque(r)

i = 0
while True:
    for num in r:
        new = que[i]*10 + num
        que.append(new)
    if que[-1] >= 10**6:
        break
    i += 1

ind = bisect.bisect_left(que, N)
#print(que)
#print(ind)
print(que[ind])

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
n = N
while True:
  tmp = n
  ng = False
  while tmp > 0:
    ng = ng or tmp%10 in D
    tmp //= 10
  if not ng:
    break
  n += 1
print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ddd = set(input().split())
while not ddd.isdisjoint(str(n)):
    n += 1
print(n)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n , k = IN()
	el=set(IN())
	for i in range(n, 1000000):
		is_ok=True
		for v in list(str(i)):
			#print(v in el)
			#print(el, v)
			if int(v) in el:
				is_ok=False
				break
		if is_ok:
			return i
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def next(v, cu):
	for i in cu:
		if i > v:
			return i
	else:
		return -1

def main():
	n, k = IN()
	al = list(IN())
	cu=[]
	for i in range(10):
		if i not in al:
			cu.append(i)
	non_zero_min = cu[0] if cu[0] > 0 else cu[1]
	is_cu0_is_0 = cu[0]==0
	
	if n < 10:
		if n in cu:
			return n
		if n > cu[-1]:
			return non_zero_min*10+cu[0]
	
	kiriage=False
	ret=[]
	for i, v in enumerate(str(n)):
		if kiriage:
			ret.append(cu[0])
		elif int(v) in cu:
			ret.append(v)
		else:
			kiriage=True
			n = next(int(v),cu)
			if n == -1:
				if i != 0:
					ret.append(cu[0])
				else:
					ret.append(str(non_zero_min)+str(cu[0]))
				
				for ic in range(i-1,-1,-1):
					#print(ic)
					t=ret[ic]
					nt = next(int(t),cu)
					if nt != -1:
						#print('a', nt, int(t))
						ret[ic]=nt
						break
					elif nt == -1 and ic == 0:
						ret[ic]=str(non_zero_min)+str(cu[0])
						#print(ret)
					else:
						ret[ic]=cu[0]
			else:
				ret.append(n)
	return ''.join([str(r) for r in ret])
			
			
			
			
			
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)