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 getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
# list(map(int, input().split()))
N, K = getNM()
intlist = [i for i in range(10)]
D = getList()
for i in D:
    if i in D:
        intlist.pop(intlist.index(i))

anslist = []
def dfs(i, num):
    anslist.append(num)
    if i < 5:
        for j in intlist:
            newnum = int(str(num) + str(j))
            dfs(i + 1, newnum)

for i in intlist:
    if i != 0:
        dfs(1, i)

anslist.sort()

for i in anslist:
    if i >= N:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
Dlist=list(map(int,input().split()))
flag=True
i=0
while flag:
    ans=str(i)
    num=0
    if i>=N:
        
        for j in range(len(ans)):
            if int(ans[j]) not in Dlist:
                num+=1
            if num==len(ans):
                print(i)
                flag=False
    i+=1

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
flag = False
while True:
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        if c in use:
            flag = True
        else:
            flag = False
            break
    if flag:
        print(n)
        sys.exit()
    n += 1

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))
num = [1,2,3,4,5,6,7,8,9,0]
li = list(set(num).difference(set(L)))

flag = False
while True:
    n = str(n)
    for i in range(len(n)):
        if int(n[i]) in li:
            flag = True
        else:
            flag= False
            break
    if flag:
        print(n)
        exit()
    n = int(n)
    n +=1

Submission status: Accepted

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

ans = n
flg = True
while flg:
    for s in str(ans):
        if int(s) in dd:
            ans += 1
            break
    else:
        flg = False
print(ans)

Submission status: Accepted

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

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

a,b = cin()
a = list(str(a))
x = []
for i in a:
    x.append(int(i))
c = cina()
d = {0,1,2,3,4,5,6,7,8,9}
e = d.difference(c)
s = ""
index = -1
test = 0
no = 0
for i in range(len(x)):
    check = False
    for j in c:
        if x[i]==j:
            check = True
    if check:
        for j in e:
            if j>x[i]:
                if test==0:
                    x[i] = j
                    index = i
                test += 1
                break
    else:
        no += 1

if no==len(x):
    for i in x:
        s += str(i)
elif test==0:
    q = e.difference({0})
    g = list(q)
    g.sort()
    s += str(g[0])
    ap = ""
    if 0 in e:
        ap = '0'*len(a)
    else:
        ap = str(g[0])*len(a)
    s += ap
else:
    w = list(e)
    for i in range(0,index+1):
        s += str(x[i])
    ap = str(w[0])*(len(x)-index-1)
    s += ap

print(s)



# if len(f)==0:
#     q = e.difference({0})
#     g = list(q)
#     g.sort()
#     s = ""
#     s += str(g[0])
#     ap = ""
#     if 0 in e:
#         ap = '0'*len(a)
#     else:
#         ap = str(g[0])*len(a)
#     s += ap

# s = ""
# check = False
# for i in a:
#   replace = False
#   rep = -1
#   for j in range(len(c)):
#     if int(i)==c[j]:
#       replace = True
#       break
#   if replace:
#     for k in e:
#       if k>int(i):
#         rep = k
#         break
#   else:
#     rep = i  
#   if rep == -1 and not check:
#   	check = True
#   s += str(rep)
# if check:
#   f = e.difference({0})
#   g = list(f)
#   g.sort()
#   s = ""
#   s += str(g[0])
#   ap = ""
#   if 0 in e:
#     ap = '0'*len(a)
#   else:
#     ap = str(g[0])*len(a)
#   s += ap
# else:

  
# print(s)

Submission status: Accepted

Solution code:
n,k = input().split()
hate_num = input().split()
num = int(n)
boo = False
while(boo == False):
  dec = []
  for i in str(num):
    dec.append(i not in hate_num)
    
  if(False not in dec):
    boo = True
  num += 1
    
print(num-1)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
ds = [int(x) for x in input().split()]
xs = list(filter(lambda x: x not in ds, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
o = n
m = len(str(n))
ans = 0
c = False
for i in range(m):
    d = (o // 10 ** i) % 10
    ys = list(filter(lambda x: x >= d, xs))
    if len(ys) == 0:
        if i == m - 1:
            y = xs[0] * 11 if xs[0] != 0 else xs[1] * 10
        else:
            y = xs[0]
        o += (y - d) * 10 ** i + 10 ** (i + 1)
        ans += y * 10 ** i
    else:
        y = ys[0]
        if y > d:
            ans = y * 10 ** i
            for j in range(i):
                ans += xs[0] * 10 ** j
        else:
            ans += y * 10 ** i
print(ans)

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):
    w = True
    idx = 0
    i = str(i)
    while idx < len(str(i)):
        if i[idx] in d:
            w = False
            break
        idx += 1
    if w:
        print(i)
        exit()

Submission status: Accepted

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

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

import bisect
for i in range(len(n)-1,-1,-1):
    if n[i]>ok[len(ok)-1]:
        for j in range(i,len(n)):
            n[j]=str(ok[0])
        if i>0:
            n[i-1] += 1
        else:
            if ok[0]==0:
                n.insert(0,str(ok[1]))
            else:
                n.insert(0,str(ok[0]))
    else:
        num=bisect.bisect_left(ok,n[i])
        if n[i]<ok[num]:
            for j in range(i+1,len(n)):
                n[j]=str(ok[0])
        n[i]=str(ok[num])

n=int(''.join(n))
print(n)

Submission status: Accepted

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

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

#print(not_D)
c = list(itertools.product(not_D,repeat = len(str(N))))
c += (list(itertools.product(not_D,repeat = len(str(N))+1)))

for row in c:
  num = ""
  for i in row:
    num += str(i)
  siharai.append(int(num))
#print(siharai)
  
for i in siharai:
  if i >=N:
    print(i)
    break

Submission status: Accepted

Solution code:



N,K = map(int, input().split())
D = list(map(int, input().split()))
nums = set([0,1,2,3,4,5,6,7,8,9])
nums -= set(D)
#print(nums)

ans = []
def func(s, nums):
    global ans
    if len(s) >= len(str(N)):
        if int(s) >= N:
            ans.append(int(s))

        
    if len(s) > len(str(N))+1:
        return

    for i in nums:
        func(s[:] + str(i), nums)


func("", nums)
ans.sort()
print(ans[0])

Submission status: Accepted

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

while True:
    if all(n not in D for n in str(N)):
        print(N)
        exit()
    else:
        N += 1

Submission status: Accepted

Solution code:
import itertools
NK = input().split()
N = NK[0]
K = int(NK[1])
 
d = input().split()
D = [int(s) for s in d]
 
Da = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
for i in D:
    Da.remove(i)
Da_str = [str(j) for j in Da]
 
a_1 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N))]
a_2 = [''.join(j) for j in itertools.product(Da_str, repeat=len(N)+1)]
a = a_1 + a_2
nu = [int(k) for k in a]
 
for i in nu:
    if i >= int(N):
        print(i)
        break

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())
D = set(map(str, sys.stdin.readline().rstrip().split()))


for i in range(N, N*10+1):
    price_str = str(i)
    for num_str in price_str:
        if num_str in D:
            break
    else:
        print(price_str)
        sys.exit()

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    n,k = map(int,stdin.readline().rstrip().split())
    Ds = set(map(int,stdin.readline().rstrip().split()))

    ans = n
    while True:
        num = ans
        numset = set()
        while num != 0:
            r = num%10
            num = num//10
            numset.add(r)
        if numset & Ds == set({}):
            break;
        else:
            ans+=1
    
    print(ans)
main()

Submission status: Accepted

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

number = list(range(10))
number = [str(x) for x in number if x not in d]

ans = []
for v in itertools.product(number, repeat=len(n)):
  if v[0] == "0": continue
  if int("".join(v)) >= int(n): ans.append(int("".join(v)))

if not ans:
  for v in itertools.product(number, repeat=len(n)+1):
    if v[0] == "0": continue
    if int("".join(v)) >= int(n): ans.append(int("".join(v)))

print(min(ans))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    for i in range(N, 10 ** 5):
        s = str(i)
        hated = False
        for d in D:
            if d in s:
                hated = True
        if not hated:
            ans = i
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
lst = [int(x) for x in input().split()]
while True:
    l = [s for s in str(N)]
    f = True
    for n in set([int(x) for x in l]):
        if n in lst:
            f = False
            break
    if f:
        print(N)
        exit()
    N += 1

Submission status: Accepted

Solution code:

def main():
    N, K = input().split(" ")

    D = list(input().split(" "))
    use_num = list(set([str(i) for i in range(10)]) - set(D))

    N = int(N)
    i = N
    while True:

        if not set(str(i)) <= set(use_num) and i >= N:
            i += 1
        else:
            print(i)
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
n, k = map(int, input().split())
D = list(map(int, input().split()))
ok_lst = [x for x in range(0, 10) if x not in D]
stack = deque([x for x in ok_lst if x != 0])
while len(stack) > 0:
    now_num = stack.popleft()
    if now_num >= n:
        print(now_num)
        break
    for x in ok_lst:
        next_num = str(now_num) + str(x)
        stack.append(int(next_num))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(str, input().split()))
"""
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(k):
    for j in range(len(l)):
        if d[i] == l[j]:
            l.pop(j)
            break
"""
while True:
    tmp = list(str(n))
    flag = True
    for i in range(len(d)):
        if d[i] in tmp:
            flag = False
            break
    if flag:
        break
    n += 1
print(n)

Submission status: Accepted

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

# 1行目
N,L = map(int,input().split())
mylist = []
mylist = list(map(int,input().split()))
#for i in range(N):
#  val = input()
#  if val:
#    mylist.append(val)
#  else:
#    break

i = 0
result = 0
res_bool = False
while result < 10 * N:
  result = N + i
  #print("i:{}".format(i))
  for a in str(result):
    #print("a:{}".format(a))
    if not a in [str(n) for n in mylist]:
      res_bool = True
    elif a in [str(n) for n in mylist]:
      #print("aがあった")
      res_bool =False
      break
  #print("res_bool:{}".format(res_bool))
  if res_bool:
    break
  i += 1
  
print(result)

Submission status: Accepted

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

    ans += 1

print(ans)

Submission status: Accepted

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

s = 0
while s<k and s == d[s]:
    s += 1

x = 0
y = 0
while x <4:
    if n // (10**x) >0:
        y = x
    x += 1

i = 0
a = [0]
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    i +=1

i = 0
t = 0
while i <= y + t:
    j = 0
    while j < k:
        if a[y-i+1] == d[j]:
            a[y-i+1] += 1
            if y-i+1 < y+1:
                a[y-i+2] = s
        if a[y-i+1] == 10:
            a[y-i+1] = 0
            a[y-i] +=1
        j+=1
    i+=1
    if a[0] == 1 and t == 0:
        i = 1
        while i<=y+1:
            a[i] = 0
            i += 1
        i = 0
        t = 1
        continue

i = 0
while i <= y + t:
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)

Submission status: Accepted

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

for i in range(N,88889):
    for s in str(i):
        if s in D:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import itertools
n,k = map(int,input().split())
li = list(map(int,input().split()))
se = list(map(str,set([i for i in range(0,10)]) - set(li)))
lee = len(str(n))
ans = 999999999999999999999
tmp = ''
kumi_li = list(itertools.product(se, repeat=lee+1))
kumi_2_li = list(itertools.product(se, repeat=lee))
for k in kumi_li:
    #print(k)
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
for k in kumi_2_li:
    suuji = int(''.join(k))
    if suuji <= ans and suuji >= n:
        ans = suuji
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
se = set(range(10))
for a in A:
    se ^= set([a])

def check(str_num):
    for x in str_num:
        if not int(x) in se:
            return False
    return True

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

Submission status: Accepted

Solution code:
import itertools

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

D = set(input().split())

n = [x for x in str(N)]
num = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D
judge = "no"
ans = N

for i in n:
    if i in D:
        judge = "yes"
        break

if judge == "yes":
    if ans < int(sorted(list(num))[-1] * len(n)):
        ans_list = sorted(list(itertools.product(num, repeat=len(n))))
        for i in ans_list:
            if int("".join(i)) > ans:
                ans = int("".join(i))
                break
    else:
        ans_list = sorted(list(itertools.product(num, repeat=len(n) + 1)))
        for j in ans_list:
            if int("".join(j)) > ans:
                ans = int("".join(j))
                break

print(ans)

Submission status: Accepted

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

for n in range(N, 100001):
    for s in str(n):
        if s in D:
            break
    else:
        print(n)
        exit()

Submission status: Accepted

Solution code:
def getDigits(n):
  digits = []
  while n > 0:
    digits.append(n % 10)
    n //= 10
  return digits

def firstValidNumber(n, digits):
  while True:
    isValid = True
    currentDigits = getDigits(n)
    for digit in currentDigits:
      if digit in digits:
        isValid = False
        break
    if isValid:
      return n
    n += 1
  return n

n, k = map(int, input().split())
digits = list(map(int, input().split()))
print(firstValidNumber(n, digits))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
res = []


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))
    Available = []

    for i in range(10):
        if i not in D:
            Available.append(str(i))


    def dfs(Price):
        if len(Price) == 5:
           return

        for value in Available:
            Price.append(value)
            res.append(int("".join(Price)))
            dfs(Price)
            Price.pop()

    dfs([])

    ans = f_inf
    for i in res:
        if i >= n:
            ans = min(ans, i)
    
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:

import sys

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

def f():
    q = []

    for i in filter(lambda x: x not in d, range(10)):
        q.append(i)

    while len(q) != 0:
        x = q.pop(0)

        if x >= n:
            print(x)
            break

        for i in filter(lambda x: x not in d, range(10)):
            q.append(x * 10 + i)

f()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(map(str, input().split()))
f = True
while f:
    if set(list(str(N))) == set(list(str(N))) - D:
        print(N)
        f = False
    else:
        N += 1

Submission status: Accepted

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

while flag == True:   
    temp = list(str(N))
    if set(temp) == set(temp) - number:
        print(N)
        flag = False
    else:
        N = N + 1

Submission status: Accepted

Solution code:
n , k = map(int, input().split())
ns = str(n)
d = set(list(map(int,input().split())))
s = set([0,1,2,3,4,5,6,7,8,9])
l = s-d
le = len(ns)
ans = 0
c=0
k=0
for i in range(le):
    for j in range(10-n%10-k):
        if n%10+j+k in l:
            ans += n%10+j+k
            if j+k != 0:
                ans=int(ans)
            c=1
            k=0
            break
    if c ==0:
        ans +=min(l)
        k=1
    c=0
    n//=10
    ans/=10
z=set([0])
l2=l-z
if k==1:
    ans+=min(l2)
    ans = int(ans)
for i in range(le):
    ans *=10
    if ans%10 ==0:
        ans+=min(l)
print(int(ans))

Submission status: Accepted

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

result = N
while True:
  for a in array:
    if a in list(result):
      break
  else:
    break
  result = str(int(result) + 1)
print(result)

Submission status: Accepted

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

while True:
    str_n = str(n)
    hantei = 1
    for i in range(len(str_n)):
        if int(str_n[i]) in d: hantei = 0
    if hantei == 1: break
    n += 1

print(n)

Submission status: Accepted

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    D = input().split()
    i = N
    while True:
        for s in str(i):
            if s in D:
                i += 1
                break
        else:
            print(i)
            return
    raise Exception("unreachable!")

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=set(map(int,input().split()))
d_=set((1,2,3,4,5,6,7,8,9,0))
abl=d_-d
ans=''
a0=True
a1=True
for i in str(n):
  if a0 and int(i) in abl:
    ans+=str(i)
  elif a0:
    b=[ai for ai in abl if int(i)<ai]
    if len(b)==0:
      a1=False
      break
    b.sort()
    ans+=str(b[0])
    a0=False
  else:
    ans+=str(min(abl))
if a1==False:
  print(str(min(abl-{0}))+str(min(abl))*len(str(n)))
else:
  print(ans)

Submission status: Accepted

Solution code:
def solve(n, k, xs):

    tmp = n
    num = len(xs)
    
    while True:
        if num == len([i for i in xs if i not in str(tmp)]):
            break
        else:
            tmp += 1
    
    return tmp

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    xs = [i for i in input().split()]
    print(solve(n, k, xs))

Submission status: Accepted

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

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


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

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

for ii in range(n*10):
    i = ii+1
    ar = ValueToArray10(i, int(1+(math.log(i)+0.00001)/math.log(10)))
    ok=1
    for j in ar:
        for k in a:
            if(j==k):
                ok=0
    if(ok==1 and i>=n):
        print(i)
        exit()

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
d = set(inl())
for i in range(n,100000):
    a = set([])
    j = i
    while j>0:
        a.add(j%10)
        j //= 10
    if len(a&d)==0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, k=map(int, input().split())
nums=input().split()
nums=[int(x) for x in nums]

def split_to1d(x):
  
  res=[]
  while True:
    
    y=x%10
    res.append(y)

    z=x//10
    if z<1:
      break
      
    x=z
  
  return res

while True:
  
  num_list=split_to1d(n)

  for i, num in enumerate(num_list):

    is_ok=True
    if num in nums:
      is_ok=False
      break
     
  if is_ok:
    break
  else:
    n+=1
    
print(n)

Submission status: Accepted

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

for q in range(100000):
    if not set(sorted({int(str(q)[i]) for i in range(len(str(q)))})) & d:
        if q >= n:
            print(q)
            exit(0)

Submission status: Accepted

Solution code:
import sys

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

number = N-1
while True:
    number += 1
    ng = False
    for i in range(K):
        if Ds[i] in str(number):
            ng = True
            break

    if ng == False:
        print(number)
        sys.exit(0)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
sset = set(i for i in range(1,10)) - set(d)

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
d_set = {x for x in input().split()}

for i in range(n, 100000):
    i_set = set(str(i))
    if(len(i_set & d_set) == 0):
        print(i)
        break

Submission status: Accepted

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

def main():
    N, K = map(int, readline().rstrip().split())
    D = set(readline().rstrip().split())
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e in D:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N, K = map(int, readline().rstrip().split())
    D = list(map(int, readline().rstrip().split()))
    nums = [str(i) for i in range(10)]
    for d in D:
        nums.remove(str(d))
    for i in range(N, N*10+1):
        d = str(i)
        flg = True
        for e in d:
            if e not in nums:
                flg = False
                break
        
        if flg:
            print(i)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! python3
def main():
    n, k = map(int, input().split())
    hate = set(input().split())

    while True:
        nset = set(list(str(n)))
        l = nset&hate
        if len(l) == 0:
            print(n)
            break

        n += 1

main()

Submission status: Accepted

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

for i in range(n,1000001):
    for j in d:
        if str(i).count(str(j))>=1:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, k = map(int, input().split())
    lst = list(map(int, input().split()))

    while True:
        flag = True
        for char in str(n):
            if int(char) in lst:
                flag = False
                break
        if flag:
            break
        n += 1
    print(n)

Submission status: Accepted

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

check = n
while True:
    can = True
    for letter in str(check):
        if letter in d_ls:
            can = False
    if can:
        break
    check += 1
print(check)

Submission status: Accepted

Solution code:
cost,n = map(int,input().split())
cash = [int(x) for x in input().split()]

#account = cost - 1
flag = False
while flag == False :
    flag = True
    for i in range(len(cash)):
        if str(cash[i]) in str(cost):
            flag = False
            break
    if flag == False:
        cost += 1
    else:flag=True
        

print(cost)

Submission status: Accepted

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


def solve(N: int, K: int, D: "List[int]"):
    while any([str(i) in str(N) for i in D]):
        N += 1

    print(N)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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, k = map(int, input().split())
D = list(input().split())

for i in range(n, n*10+1):
    t = str(i)
    isok = True
    for d in D:
        if d in t:
            isok = False
            break
    if isok:
        print(t)
        exit()

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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


def ok(X):
    for d in D:
        if str(d) in str(X):
            return False
    return True

while not ok(N):
    N += 1

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l=list(map(int,input().split()))
d=list(map(int,input().split()))
u={i for i in range(10)}
d_bar=u-set(d)
d_bar={str(i) for i in d_bar}
n=l[0]
n_set=set(str(n))
while True:
    if n_set<=d_bar:
        print(n)
        break
    n=n+1
    n_set=set(str(n))

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)