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: Time Limit Exceeded

Solution code:
#入力
n, k = map(int, input().split())
d = input().split()

while (n < 10000):
  a = str(n)
  flag = 1
  for i in range(len(a)):
    for j in range(k):
      if a[i] != d[j]:
        flag += 1
      else:
        n += 1
        break
    if (flag % (k+1)) != 0:
      break
  if flag == len(a) * (k+1):
    break
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def is_dislike_number(number, dislike_list):
  if number in dislike_list:
    return True
  else:
    return False

while True:
  for i, num in enumerate(str(n)):
    num = int(num)
    if is_dislike_number(num, d_list):
      n += 1
      break
  print(n)

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
Ds=list(input().split())
Di=list(map(int,Ds))
nex=[1]*10
for i in reversed(Di):
    nex[i-1]=nex[i]+1

def check(n):
    ns = str(N)
    for nss in ns:
        if nss in Ds:
            return False
    return True

def next(i):
    global N
    ns='{0:0>4}'.format(N)
    t=nex[int(ns[i])]
    pp=int(ns[i])+t
    if pp >=10:
        t=t-10
        N+=t*(10**(3-i))
        next(i-1)
    else:
        N+=t*(10**(3-i))

while not check(N):
    next(3)
print(N)

Submission status: Accepted

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

f = [0]*10
for d in D:
    f[d] = 1

while True:
    check = str(n)
    for c in check:
        if f[int(c)]:
            n += 1
            break
    else:
        print(check)
        break

Submission status: Accepted

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

for i in range(n, 100000):
  m = str(i)
  count = 0
  for j in range(len(m)):
    if int(m[j]) in D:
      break
    else:
      count += 1
    if count == len(m):
      print(i)
      exit()
      
print(0)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
ng = [False] * 10
for i in d:
    ng[i] = True
def ok(n):
    global ng
    while n > 0:
        if ng[n%10]:
            return False
        n //= 10
    return True
while not ok(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) != 0:
    n+=1
    
  else:
    print(n)
    break

Submission status: Accepted

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

def check(x) -> bool:
    while x>0:
        a = x%10
        if a in d:
            return False
        x//=10
    return True

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

Submission status: Accepted

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

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))

Submission status: Accepted

Solution code:
def is_dislike(N, ds):
  num = N
  while(True):
    if (num % 10) in ds:
      return True
    else:
      num = int(num / 10)
      if num == 0:
        break
  return False


nk = list(map(int,input().split()))
N = nk[0]
K = nk[1]
ds = list(map(int,input().split()))
while(True):
  if is_dislike(N, ds):
    N = N+1
  else:
    print(N)
    break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d=set(input().split())
while True:
    if len(set(str(n))&d)!=0:
        n+=1
    else:
        break
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) != 0:
    n+=1
    
  else:
    print(n)
    break

Submission status: Accepted

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

def solve(n):
  digits = str(n)
  for digit in digits:
    if int(digit) in d:
      return False
  return True

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

Submission status: Accepted

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

while True:
  if len(set(str(N)) & bl) != 0:
    N += 1
  else:
    print(N)
    break

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

while True:
    n = str(N)
    for i in range(K):
        f = 0
        if D[i] in n:
            N += 1
            f = 1
            break
    if f == 0:
        break

print(N)

Submission status: Accepted

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

def judge(num):
    for i in str(num):
        if i in unlike_list:
            return False
    return True

ans = False
while not ans:
    if judge(N):
        ans = True
    else:
        N += 1

print(N)

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    A_list = list(map(str, input().split()))
    use_list = ["0","1","2","3","4","5","6","7","8","9"]
    list_A = list(set(use_list) - set(A_list))
    #print("list_A", list_A)
    for i in range(100000) :
        ans = N + i
        #print("ans", ans)
        ans_str = str(ans)
        frag = 0
        for val in ans_str :
            #print("val", val)
            if str(val) in list_A :
                pass
                #print("frag", frag)
            else :
                frag = 1
                break

        if frag == 0 :
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# N, Kの入力受付
N, K = map(int, input().split())
# Dの入力受付
D = set(input().split())
# 0-9とDの差集合作成、リスト化してEに代入
E = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D
# Nに1ずつ足して条件に合う最初の数字を特定する
result = False
while result == False:
    for i in str(N):
        if not i in E:
            N = N + 1
            result = False
            break
        else:
            result = True
print(N)

Submission status: Accepted

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

def f(x):
    x=str(x)
    x=list(x)
    for i in x:
        if int(i) in d:
            return False
    return True

ans=n

while f(n)==False:
    n+=1
print(n)

Submission status: Accepted

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

def f(x):
    x=str(x)
    x=list(x)
    for i in x:
        if int(i) in d:
            return False
    return True

ans=n

while not f(n):
    n+=1
print(n)

Submission status: Accepted

Solution code:
n, k= input().split()
l = list(map(int,input().split()))
checkNum=[i for i in range(11)]

def find(x):
    while x!=checkNum[x]:
        checkNum[x]=checkNum[checkNum[x]]
        x=checkNum[x]
    return x

for i in l:
    checkNum[find(i)]=checkNum[find(i+1)]

fin=""
for i in range(len(n)):
    first=int(n[i])
    k=find(first)
    if k==first:
        fin+=str(k)
    else:
        if k!=10:
            fin=str(k)+str(find(0))*(len(n)-i-1)
        else:
            fin=str(find(1))+str(find(0))*len(n)
        break

print(fin)

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()
d = LI()

limit = 11*n
while n < limit:
    flg = 1
    for x in list(str(n)):
        if int(x) in d:
            flg = 0
            break
    if flg:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n, k = LI()
# n = [int(x) for x in str(n)]
d = set(LI())
notd = list(set(range(10)) - d)
q = deque()
q.appendleft(0)
cnt = 0
ans = []
num = []

# while q:
#     now = q.popleft()
#     cnt += 1
#     if cnt > len(n):
#         ans.append(int("".join(list(map(str, num)))))
#         num = []
#         cnt = 0

#         continue
#     for x in notd:
#         if now in notd:
#             continue
#         num.append(x)
#         q.appendleft(x)

# print(min([x for x in ans if x >= n]))
limit = 11*n
while n < limit:
    flg = 1
    for x in list(str(n)):
        if int(x) in d:
            flg = 0
            break
    if flg:
        print(n)
        break
    n += 1

Submission status: Accepted

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

for i in range(n, 100001):
    flg = True
    s = str(i)
    for j in range(len(s)):
        if s[j] in a:
            flg = False
            break
    if flg:
        break
print(i)

Submission status: Accepted

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

i = n
while True:
    money = list(map(int, str(i)))
    for m in money:
        if dl.count(m) != 0:
            break
    else:
        print(i)
        break
    i += 1

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())

#dic = defaultdict(int)
n,k = readInts()
D = Counter(readInts())
def ok(n):
    while n:
        v = n%10
        if D[v]:
            return False
        n //= 10
    return True
ans = n
for i in range(n, 100000):
    if ok(i):
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('unko')

    @cc.export('main', '(i4, i4, i4[:])')
    def main(n, k, a):
        for i in np.arange(n, 100000):
            ok = 1
            j = i
            while j:
                m = j % 10
                for l in a:
                    if m == l:
                        ok = 0
                j //= 10
            if ok:
                print(i)
                break
    cc.compile()
    exit()


if __name__ == '__main__':
    from unko import main
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Submission status: Accepted

Solution code:
import sys
import numpy as np
from numba import njit, i4
read = sys.stdin.readline


@njit((i4, i4, i4[:]), cache=True)
def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = 1
        j = i
        while j:
            m = j % 10
            for l in a:
                if m == l:
                    ok = 0
            j //= 10
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        for j in str(i):
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = set(read().split())
    main(n, k, a)

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in np.arange(n, 100000):
        ok = True
        j = i
        while j:
            ok &= j % 10 not in a
            j //= 10
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int32, sep=' ')
    a = np.fromstring(read(), dtype=np.int32, sep=' ')
    main(n, k, a)

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n,k = MI()
d = RI()

for i in range(n,100000):
    a = str(i)
    flag = True
    for j in a:
        if int(j) in d:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
E = []
for i in range(10):
    if i not in D:
        E.append(i)
E = sorted(E)
N = str(N)
ind = len(N)
for i in range(len(N)):
    if int(N[i]) not in E:
        ind = i
        break
if ind==len(N):
    print(N)
else:
    flag = 0
    x = ""
    for i in range(ind,-1,-1):
        n = int(N[i])
        for e in E:
            if e>n:
                x = N[:i]+str(e)+str(E[0])*(len(N)-i-1)
                flag = 1
                break
        if flag==1:break
    if flag==0:
        if E[0]>0:
            a = E[0]
        else:
            a = E[1]
        x = str(a)+str(E[0])*len(N)
    print(x)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
l = list(map(str, input().split()))
 
for i in range (N, 100000): 
	k = str(i)
	counter = 0
	for j in range (0, K):
		if k.find(l[j]) >= 0:
			counter+=1
	if counter == 0:
		print(i)
		exit()

Submission status: Accepted

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

while (True):
  if len(set(str(M)) & D) == 0:
    break
  M += 1
print(M)

Submission status: Accepted

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

for k in range(N,10**9):
    f = 1
    for e in str(k):
        if e in D:
            f = 0
            break
    if f == 1:
        print(k)
        exit(0)

Submission status: Accepted

Solution code:
import sys
import numpy as np
read = sys.stdin.readline


def main(n, k, a):
    for i in range(n, 100000):
        s = np.array(list(map(int, str(i))), dtype=np.int64)
        ok = True
        for j in s:
            ok &= j not in a
        if ok:
            print(i)
            break


if __name__ == '__main__':
    n, k = np.fromstring(read(), dtype=np.int64, sep=' ')
    a = np.fromstring(read(), dtype=np.int64, sep=' ')
    main(n, k, a)

Submission status: Accepted

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

n_l = list(map(int, list(str(n))))
if len(set(safe)&set(n_l)) == len(set(n_l)):
    print(n)
    exit()

for v in itertools.product(safe, repeat=len(str(n))):
    if v[0] == 0: continue
    x = int("".join(list(map(str, v))))
    if int(x) >= n:
        print(x)
        exit()

for v in itertools.product(safe, repeat=len(str(n))+1):
    if v[0] == 0: continue
    x = int("".join(list(map(str, v))))
    if int(x) >= n:
        print(x)
        exit()

Submission status: Accepted

Solution code:
N, K, *D = map(int, open(0).read().split())
D = set(str(d) for d in D)
for i in range(N, 100_000):
    if set(str(i)) & D:
        continue
    print(i)
    break

Submission status: Accepted

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')


def main():

    N, K = MAPINT()
    D = LMAPSTR()
    
    str_n = str(N)
    
    for i in range(N, 100000):
      str_i = str(i)
      for s in str_i:
        if s in D:
          break
      else:
        print(str_i)
        exit()

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[21]:


import itertools

def main():
	N, K = [int(n) for n in input().split(" ")]
	D = [1] * 10
	for d in input().split(" "):
		D[int(d)] = 0
	L = [str(i) for i, v in enumerate(D) if v == 1]

	digit = len(str(N))
	cand = []
	for n in list(itertools.product(L, repeat=digit)):
		p = int("".join(list(n)))
		if p >= N:
			cand.append(p)
	if len(cand):
		print(min(cand))
	else:
		if L[0] == "0":
			print(str(L[1]) + "0" * digit)
		else:
			print(str(L[0]) * (digit + 1))


main()


# In[ ]:

Submission status: Accepted

Solution code:
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)

if __name__ == '__main__':
    # ------ 入力 ------#
    nk = list(map(int, input().split()))     # スペース区切り連続数字

    x = nk[1]
    dList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    f = 0
    n = nk[0]
    while f == 0:
        nList = [int(c) for c in str(n)]  # 数字→単数字リスト変換
        b = 1
        for i in nList:
            for j in dList:
                if i == j:
                    b = 0
                    break
        if b == 1:
            break
        else:
            n += 1

    # ------ 出力 ------#
    print("{}".format(n))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N,K=mint()
D=lint()
S=set([str(d) for d in D])

for x in range(N,100000):
    s=str(x)
    tmp=True
    for i in range(len(s)):
        if s[i] in S:
            tmp=False
            break
    if tmp:
        print(x)
        exit()

Submission status: Accepted

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


def f(n, x):
    if n==0:
        if x >= N:
            print(x)
            exit()
        return
    
    for i in range(10):
        if i in D:
            continue
        f(n-1, x*10+i)

f(len(str(N)), 0)
ans = ""
for i in range(1, 10):
    if i not in D:
        ans = str(i)
        break
for i in range(10):
    if i not in D:
        ans += str(i)*len(str(N))
        break
print(ans)

Submission status: Accepted

Solution code:
def iparse():
    return list(map(int, input().split()))

n, k = iparse()
d = iparse()

for i in range(n, 5000000):
    tmp = i
    f = True
    while tmp > 0:
        x = tmp % 10
        if x in d:
            f = False
            break
        tmp //= 10
    if f:
        print(i)
        exit()

Submission status: Accepted

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


def val(n):
    for i in str(n):
        if i in d:
            return
    print(n)
    exit()


while True:
    val(str(n))
    n += 1

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
if k == 0:
  print(n)
  exit()
dislike = list(input().split())
 
ans = n-1
flag = 1
while flag == 1:
  ans+=1
  flag = 0
  for i in str(ans):
    if i in dislike:
      flag = 1
      break
print(ans)

Submission status: Accepted

Solution code:
n,k = [int(x) for x in input().split()]
ds = {int(x) for x in input().split()}
ns = {0,1,2,3,4,5,6,7,8,9} -ds
#print(ds)
#print(ns-ds)
temp=0
d ={}
a=1
b = {}
m = len(str(n)) +1 
over=False
while(a<=m and not over ):
  c = []
  d = 10**(a-1) 
  for v in ns:
    if a>1:
      for bv in b[a-1]:
        t = v*d + bv
        c += [t]
        if t >= n:
          print(t)
          over=True
          break
      if over:
        break
    else:
      t = v*d
      c += [t]
      if t >= n:
          print(t)
          over=True
          break
      
  b[a] = c
  a+=1
  
#for j in b:    
#    print(j,b[j])

Submission status: Accepted

Solution code:
from itertools import product
N, K = map(int, input().split())
D = list(map(int, input().split()))
canuse = {0,1,2,3,4,5,6,7,8,9} - set(D)
canuse = list(canuse)
ans = float("inf")
for d in range(1, 6):
    for num in product(canuse, repeat=d):
        number = ""
        for m in num:
            number += str(m)
        number = int(number)
        if number >= N:
            ans = min(number, ans)
        
print(ans)

Submission status: Accepted

Solution code:
import itertools

def cal(N, target_num, keta):
    answer = float('inf')
    for p in itertools.product(target_num, repeat=keta):
        temp = 0
        for i, num in enumerate(p):
            temp += num * 10**i
            
        if temp >= N:
            answer = min(answer, temp)

    return answer

if __name__ == "__main__":
    N, K = map(int, input().split()) # N円の品物、K個の嫌いな数字
    D = set(list(map(int, input().split()))) # 嫌いな数字のリスト
    base = set(range(10))

    target_num = base - D
    keta = len(str(N))

    answer = min(cal(N, target_num, keta), cal(N, target_num, keta+1))

    print(answer)

Submission status: Accepted

Solution code:
import itertools

N, K = map(int, input().split()) # N円の品物、K個の嫌いな数字
D = set(list(map(int, input().split()))) # 嫌いな数字のリスト
base = set(range(10))

target_num = base - D
keta = len(str(N))

answer = float('inf')
for p in itertools.product(target_num, repeat=keta):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
        
    if temp >= N:
        answer = min(answer, temp)

for p in itertools.product(target_num, repeat=keta+1):
    temp = 0
    for i, num in enumerate(p):
        temp += num * 10**i
        
    if temp >= N:
        answer = min(answer, temp)

print(answer)

Submission status: Accepted

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

while (s >= set(str(n))) == False:
  n += 1
  if (s >= set(str(n))) == True:
    ans = n
    break
    
print(ans)

Submission status: Accepted

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

while True:
  S=str(N)
  flag=True
  for x in S:
    if int(x) in D:
      flag=False
  if flag==True:
    break;
  N+=1
print(N)