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(int,input().split())
a=list(map(int,input().split()))

for i in range(1,10**5+1):
  if i>=n:
    p=str(i)
    ch=0
    for y in range(len(p)):
      if int(p[y]) in a:
        ch+=1
    if ch==0:
      print(i)
      break

Submission status: Accepted

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

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

print(n)

Submission status: Accepted

Solution code:
n, k = [int(x) for x in input().split()]
d_set = set(input().split())
while True:
    if len(set(str(n)).intersection(d_set)) == 0:
        break
    n += 1
print(n)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
kingaku, n = input().split()
no_num = input().split()
ok_num = [str(i) for i in range(10) if not str(i) in no_num]
result = []
 
for i in kingaku:
    for j in ok_num:
        if i == j:
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    else:
        n = 1 if ok_num[0] == '0' else 0
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()
 
print(''.join(result))

Submission status: Accepted

Solution code:
kingaku, n = input().split()
no_num = input().split()
ok_num = []
result = []

for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        n = 0
        if ok_num[0] == '0':
            n = 1
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()

print(''.join(result))

Submission status: Accepted

Solution code:
kingaku, n = input().split()
no_num = input().split()
result = []
ok_num = []
kuriage_num = [-1, 0]

def kuriage(l):
    for i in ok_num:
        if result[l] < i:
            kuriage_num = [l, i]
            return
    if l <= 0:
        return
    return kuriage(l-1)

#使える数字のリストを作成
for i in range(10):
    if not str(i) in no_num:
        ok_num.append(str(i))

set_flg = False
for i in kingaku:
    set_flg = True
    for j in ok_num:
        if i == j:
            set_flg = False
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    
    if set_flg:
        n = 0
        if ok_num[0] == '0':
            n = 1
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()

print(''.join(result))

Submission status: Accepted

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

d = set()
for i in range(K):
    d.add(str(D[i]))
# print(d)

for i in range(N, 100000):
    flag = True
    s = str(i)
    li = list(s)
    for nowletter in li:
        if nowletter in d:
            flag = False
    if flag:
        print(i)
        exit()

Submission status: Accepted

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

d = set()
for i in range(K):
    d.add(str(D[i]))


for i in range(N, 100000):
    s = str(i)
    li = list(s)
    nowset = set(li)
    if not nowset & d:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

C = list({0,1,2,3,4,5,6,7,8,9}-D)
C.sort()
num = len(N)

def minimum(x,ans):
    ans += str(min(C))*x
    return ans

ans = ''
if C[-1]<int(N[0]):
    C_0 = list(set(C)-{0})
    ans += str(min(C_0))
    ans = minimum(num,ans)
    print(ans)
    exit()

points = 0
for i in range(0,num):
    minus = 0
    for j in range(len(C)):
        if C[j]==int(N[i]):
            ans += str(C[j])
            points += 1
            break
        elif C[j]>=int(N[i]):
            ans += str(C[j])
            ans = minimum(num-i-1,ans)
            print(int(ans))
            exit()
            points = 0
        else:
            minus += 1
    if points == i and minus == len(C):
        ans = ''
        C_0 = list(set(C)-{0})
        ans += str(min(C_0))
        ans = minimum(num,ans)
        print(ans)
        exit()

print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    D = set(input().split())
    for I in range(N,10**6):
        if set(str(I)).isdisjoint(D):
            print(I)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
N, K = map(int, input().split())
nums = list(map(str, input().split()))
can_use_nums = set([str(i) for i in range(10)])
for num in nums:
    can_use_nums.remove(num)
# print(can_use_nums)

queue = deque([[num] for num in can_use_nums if num != '0'])
# print(queue)
min_num = float('inf')
while queue:
    num = queue.popleft()
    if N <= int(''.join(num)):
        min_num = min(min_num, int(''.join(num)))
    else:
        for add_num in can_use_nums:
            t_num = num.copy()
            if min_num > int(''.join(num) + add_num):
                t_num.append(add_num)
                queue.append(t_num)
print(min_num)

Submission status: Accepted

Solution code:
N, _ = input().split()
N = int(N)
dislike = list(map(int, input().split()))
like = []
f = True
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
x = N
for i in l:
    if i not in dislike:
        like.append(i)
like = list(str(like))
dislike = list(str(dislike))
while f:
    x = list(str(x))
    for i in x:
        if i not in dislike:
            f = False
        else:
            f = True
            break
    x = int("".join(x)) + 1

if x != 0:
    x -= 1
print(x)

Submission status: Accepted

Solution code:
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-13 22:50
# @url:https://atcoder.jp/contests/abc042/tasks/arc058_a

import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n,k=map(int,input().split())
    d=list(map(int,input().split()))
    mx=100000
    ans=100000
    while mx>=0:
        temp=str(mx)
        f=True
        for i in range(len(temp)):
            if int(temp[i]) in d:
                f=False
                break
        if f and mx>=n:
            ans=min(ans,mx)
        mx=mx-1
    print (ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(n, n*10):
    a = set(str(i))
    for l, m in enumerate(a):
        if m in d:
            break
        elif l == len(a)-1:
            print(i)
            sys.exit()

Submission status: Accepted

Solution code:
n,k,*d=map(int,open(0).read().split())

for p in range(n,10**5):
    tmp=p
    d1=tmp%10

    while tmp>0 and d1 not in d:
        tmp//=10
        d1=tmp%10
    
    if tmp==0:
        print(p)
        exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = set(map(int,input().split()))
#A = set(A)
ok = []
for i in range(10):
  if i not in A:
    ok.append(i)
#print(ok)
while True:
  nstr = str(N)
  nstr = list(nstr)
  #print(nstr)
  Flag = True
  for x in nstr:
    x = int(x)
    if x in A:
      Flag = False
      break
  #print(Flag)
  if Flag:
    print(N)
    exit()
  else:
    N += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(map(int, input().split()))
ok = set(range(10))
ans = 0
for i in range(n, 100000):
    ans = i
    flag = False
    while i != 0:
        if i % 10 in d:
            flag = True
            break
        i = i // 10
    if not flag:
        print(ans)
        break

Submission status: Accepted

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

for i in range(N,N+10**6+5):
  if not set(str(i)).intersection(D):
    print(i)
    exit()

Submission status: Accepted

Solution code:
N,K,*D = map(int, open(0).read().split())
Ds = set(D)
item = set([0,1,2,3,4,5,6,7,8,9]) - Ds
strs = set(str(x) for x in item)
for i in range(N,10000):
    s = set(str(i))
    if s.issubset(strs):
        print(i)
        break
else:
    il = list(item)
    il.sort()
    if il[0] == 0:
        ans = [str(il[1])] + ([str(il[0])]*len(str(N)))
        print(''.join(ans))
    else:
        ans = ([str(il[0])]*(len(str(N))+1))
        print(''.join(ans))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while 1:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S and N >= 10:
        N += 1
        continue
    if int((N%1000-N%100)/100) in S and N >= 100:
        N += 1
        continue
    if int((N%10000-N%1000)/1000) in S and N >= 1000:
        N += 1
        continue
    if int((N%100000-N%10000)/10000) in S and N >= 10000:
        N += 1
        continue
    break
print(N)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
S = {int(x) for x in input().split()}
flag = False
while flag == False:
    if N%10 in S:
        N += 1
        continue
    if int((N%100-N%10)/10) in S and N >= 10:
        N += 1
        continue
    if int((N%1000-N%100)/100) in S and N >= 100:
        N += 1
        continue
    if int((N%10000-N%1000)/1000) in S and N >= 1000:
        N += 1
        continue
    if int((N%100000-N%10000)/10000) in S and N >= 10000:
        N += 1
        continue
    flag = True
print(N)

Submission status: Accepted

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

flag=0

for i in range(100000):
    S=N+i
    flag=0
    for j in range(len(str(S))):
        if int(str(S)[j]) not in d:
            flag+=1
            if flag==len(str(S)):
                print(S)
                break
    else:
        continue
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ng = [False]*10
    for d in D:
        ng[d] = True

    for n in range(N, 10*N+1):
        d = str(n)
        flg = True
        for i in range(len(d)):
            if ng[int(d[i])]:
                flg = False
        if flg:
            print(n)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
d = LIST()
num = []
for i in range(10):
    if i not in d:
        num.append(i)
ans = inf
for i in range(5):
    for x in product(num,repeat=i+1):
        tmp = 0
        for j in range(i+1):
            tmp += x[j]*10**j
        if tmp >= n:
            ans = min(ans, tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

while i < 10*N:
    j = list(str(i))
    if not set(j).isdisjoint(set(s)): #NがSを含むとき
        i += 1
    else:
        print(i)
        break

Submission status: Accepted

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

while 1:
    for num in dlst:
        if num in str(n):
            break
    else:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
def main():
  n, k = input().split()
  a=set(input().split())
  while True:
      n1=set(n)
      if n1 & a == set():
          print(n)
          break
      else:
          n=int(n)
          n+=1
          n=str(n)
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

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

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

m = len(str(n))
for i in range(m, m+2):
  for j in product(nums, repeat=i):
    ans = ""
    for k in j: ans += str(k)
    if int(ans) >= n:
      print(ans)
      exit()

Submission status: Accepted

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

while True:
  sN = str(N)
  flag = False
  for ins in D:
    if str(ins) in sN:
      flag = True
      break
  if flag:
  	#print(out)
  	N += 1
  else:
  	break

print(N)

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):
    flag = False
    for j in str(i):
        if int(j) in d:
            flag = True
            break
    if flag:
        continue
    exit(print(i))

Submission status: Accepted

Solution code:
N, K = [1000, 8]
DRR = [1, 3, 4, 5, 6, 7, 8, 9]



N, K = [9999, 1]
DRR = [0]


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

def calculate(n, k, drr):
    dislikes = set()

    for i in range(k):
        dislikes.add(drr[i])

    while not condition(n, dislikes):
        n += 1

    print(n)
def condition(n,dislikes):
    arr = list(map(int, str(n)))

    for i in range(len(arr)):
        if  dislikes.__contains__(arr[i]):
            return False
    return True


calculate(N, K, DRR)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,100000):
    num=list(str(i))
    num1=0
    for j in range(len(num)):
        if num[j] in d:
            num1=1
            break
    if num1==0:
        print(i)
        break

Submission status: Accepted

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

for i in range(n,100000):
  i2=str(i)
  for m in d:
    if m in i2:
      break
  else:
    print(i)
    exit()

Submission status: Accepted

Solution code:
def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
def solve():
    n,k=map(int,input().split())
    s=input().split()
    s=set(s)
 
    while True:
        if check(n,s):
            print(n)
            break
        else:
            n+=1
for _ in range(1):
    solve()

Submission status: Accepted

Solution code:
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
    

    
def solve():
    n,k=mp()
    s=input().split()
    s=set(s)

    while True:
        if check(n,s):
            print(n)
            break
        else:
            n+=1
        

        
        

for _ in range(1):
    solve()

Submission status: Accepted

Solution code:
i = 0
k_n = []
k_n_all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

p_price, k_number = map(int, input().split())
k_n = map(int, input().split())
result_number = list(set(k_n_all) - set(k_n))
result_price = p_price

while True:
    x = 0
    y = 0
    z = list(map(int, str(result_price)))
    while x < len(z):
        if z[x] in result_number:
            y += 0
        else:
            y += 1
        x += 1

    if y == 0:
        print(result_price)
        break
    else:
        result_price += 1

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    D = set(LSS())

    for i in range(N, N * 10 + 1):
        if [(j in D) for j in str(i)].count(True) == 0:
            print(i)
            break

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(input().split())
ans=0
for i in range(n,100001):
  cnt=list(str(i))
  for j in range(len(cnt)):
    if cnt[j] in a:
      ans=1
      break
  if ans==0:
    print(i)
    exit()
  else:
    ans=0
    continue

Submission status: Accepted

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

while True:
    l=list(str(n))
    for i in l:
        if i in D:
            break
    else:
        break
    n+=1
    
print(n)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    D = set(map(int,input().split()))

    while True:
        flg = 0
        for i in str(n):
            i = int(i)
            if i in D:
                flg = 1
                break
        if flg == 0:
            break
        n+=1

    print(n)

main()

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    cuse = list(set(d) ^ set(range(10)))
    for i in range(n, 200000):
        nyoso = list(set(map(int, list(str(i)))))
        bit = 0
        for j in nyoso:
            if j in cuse:
                bit += 1
            else:
                break
        if bit == len(nyoso):
            print(i)
            break
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

for n in range(N, N * 10 + 1):
    ok = True
    for c in str(n):
        if c in D:
            ok = False
    if ok:
        print(n)
        break

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

for n in range(N, 100000):
    s = str(n)
    ok = True
    for c in s:
        if c in D:
            ok = False
    if ok:
        print(n)
        break

Submission status: Accepted

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

allowed = {i for i in range(10) if i not in d}
maxn = 10**5

for k in range(1,maxn+1):
    if k >= n and all(int(c) in allowed for c in str(k)):
        print(k)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ar=list(map(int,input().split()))
def f(n):
    s=str(n)
    for el in ar:
        if(str(el) in s):
            return 0
    return 1
while(not f(n)):
    n+=1
print(n)

Submission status: Accepted

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

allowed = {i for i in range(10) if i not in d}

MAXN = 10 ** 5


def answer():
    for k in range(1, MAXN + 1):
        if k >= n and all(int(c) in allowed for c in str(k)):
            return k


answer = answer()
print(answer)

Submission status: Accepted

Solution code:
def main():
  n,k=input().split()
  a=set(input().split())
  while True:
      n1=set(n)
      if n1 & a == set():
          print(n)
          break
      else:
          n=int(n)
          n+=1
          n=str(n)
  
  
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(list(input().split()))
while N < 10 ** 6:
    if len(set(list(str(N))) & D) == 0:
        print(N)
        exit()
    N += 1

Submission status: Accepted

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

i=n
while True:
    check=0
    for number in d:
        if not number in str(i):
            continue
        else:
            check=1
            break
    if check==0:
        print(i)
        break
    else:
        i+=1

Submission status: Accepted

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

n_str = str(n)
l = len(n_str)
a = [i for i in range(10) if i not in d]

#同じ桁の時
ans = ""
for i in range(l):
    for j in a:
        if j == int(n_str[i]):
            ans += str(j)
            break
        elif j > int(n_str[i]):
            ans += str(j) + str(a[0])*(l-i-1)
            print(ans)
            exit()

if len(ans)>0:
    if int(ans) >= n:
        print(ans)
        exit()

if 0 in a:
    ans = str(a[1]) + str(a[0])*l
else:
    ans = str(a[0])*(l+1)

print(ans)

Submission status: Accepted

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

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

while True:
    n = str(N)
    nn = str(N)

    for o in nn:
        if o in D:
            N += 1
            nn = str(N)
            break

    if n == nn:
        break

print(N)

Submission status: Accepted

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

def main():


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

    numList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

    num = set()
        
    for i in numList:
        if i not in D:
            num.add(i)
    

    for i in range(N, N * 10 + 1):
        setI = set(int(x) for x in list(str(i)))
        if len(num | setI) <= len(num):
            ans = i
            break
                
    print(ans)


if __name__ == "__main__":
    main()