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())
D = [int(i) for i in input().split()]

for i in range(N, 99999) :
  chk = [int(i) for i in str(i)]
  if len(set(chk) & set(D)) == 0:
    print(i)
    break

Submission status: Accepted

Solution code:
# 入力 : 横並びの数字N個（リスト内包表記で）
N, K = map(int, input().split())
set_D = {str(int(x)) for x in input().split()}

ans = N

while True :
    if set(str(ans)).intersection(set_D) :
        ans += 1
    else :
        break

print(ans)

Submission status: Accepted

Solution code:
s = input().split(" ")
n = int(s[0])
numbers = [ i for i in input() if i != " "]
 
for i in range(n, 100001):
  found = False
  snum = str(i)
  for num in numbers:
    if num in snum:
      found = True
      break
  
  if found == False:
     print(i)
     break

Submission status: Accepted

Solution code:
from itertools import product
N, K = map(int, input().split())
D = set(map(int, input().split()))
C = set(i for i in range(10))
C -= D
B = sorted(str(c) for c in C)
for i in range(1, 10):
    for p in product(B, repeat=i):
        s = "".join(p)
        if int(s) >= N:
            print(s)
            exit()

Submission status: Accepted

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

while True:
    flag = True
    str_N = str(N)
    for i in range(len(str_N)):
        if str_N[i] in D:
            flag = False
    if flag:
        print(N)
        exit()
    N += 1

Submission status: Accepted

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

Submission status: Accepted

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

while flag:
    for c in str(n):
        if c in d:
            n += 1
            break
    else:
        flag = False
    
print(n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
for n in range(N, 100000):
  if set(str(n)).isdisjoint(D): break
print(n)

Submission status: Accepted

Solution code:
import itertools

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

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

for i in D:
    if i in default:
        default.remove(i)
price=[]
for cost in itertools.product(default, repeat=len(str(N))):
    price.append(int(''.join(list(map(str,list(cost))))))

price.sort()

price=[i for i in price if i>=N]

if len(price)>=1:
    print(price[0])
else:
    N_len=len(str(N))
    default2 = [i for i in default if i >= 1]
    default2.sort()
    default.sort()
    print(str(default2[0])+str(default[0])*(N_len))

Submission status: Accepted

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

for i in range(N,10**5):
    l = set(list(str(i)))
    if l & D:
        continue
    print(i)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  s_l = list(str(n))
  frag = True
  for de in d:
    if de in s_l:
      frag = False
      continue
  if frag:
    print(n)
    break
  n += 1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - set(input().split())
while True:
  s = set(str(n))
  if s <= A:
    print(n)
    break
  n += 1

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(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:
N,K=map(int,input().split())
D=set(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:
nk = list(map(int, input().split()))
N = nk[0]
K = nk[1]

d = input().split()
a = True
for i in range(N, 90001):
  a = True
  for j in d:
    if str(i).count(j) > 0:
      a = False
      break
  if a:
    print(i)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_valid(A, D):
    while A > 0:
        if (A%10) in D:
            return False
        else:
            A = A//10
    return True
    
N, K = map(int, input().split())
D = list(map(int, input().split()))

while is_valid(N, D) == False:
    N += 1

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, _ = list(map(int, input().split()))
d = set(list(input().replace(" ", "")))

for i in range(N,10*N+1):
  n = str(i)
  ns = set(list(n))
  flg = False
  for t in ns:
    if t in d:
      flg = True
      break
  if flg == False:
    print(n)
    exit()
print(0)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
S = ""
ND = []
for i in range(10):
  if i not in D:
    ND.append(i)

if K == 9:
  S = str(ND[0])
  while int(S) < N:
    S = str(ND[0]) + S[:]
  print(int(S))
else:
  l = 0
  F = ND[0]
  j = 10 - K
  cnt = 0
  while F < N:
    l += 1
    s = l
    F = 0
    ju = 1
    if l == j:
      l, s = 0, 0
      j *= 10 - K
      cnt += 1
    for x in range(cnt+1):
      F += ND[s%(10 - K)] * ju
      ju *= 10
      s //= 10 - K
  print(F)

Submission status: Accepted

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

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

    Dset = set(D)

    for i in range(N, 1000000):
        for j in str(i):
            if int(j) in Dset:
                break
        else:
            print(i)
            return


    
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = input().split()
ds = input().split()
ns = {_n for _n in n} 
ds = { d for d in ds}

result = 1
while(True):
    rs = {r for r in str(result)}
    if result >= int(n) and len(rs&ds) == 0 :
        print(result)
        break
    else:
        result += 1

Submission status: Accepted

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

ans = n
flag = True

while flag:
  stans = str(ans)
  array = list(map(int, stans))
  sa = set(array)
  
  if sa & ds == set():
    flag = False
  else:
    ans += 1
    
print(ans)

Submission status: Accepted

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

ok = set(("0","1","2","3","4","5","6","7","8","9"))-set(D)

def solve(str_num):
    ans = 100000
    if str_num == "":
        for c in ok:
            if c == "0":
                continue
            ans = min(ans,solve(str_num+c))

    else:
        for c in ok:
            new_num = str_num+c
            if N <= int(new_num):
                ans = min(ans,int(new_num))
            else:
                ans = min(ans,solve(new_num))
    return ans

if N<10:
    ans = 100000
    for c in ok:
        if N <= int(c):
            ans = min(ans,int(c))
    if ans == 100000:
        print(solve(""))
    else:
        print(ans)
else:
    print(solve(""))

Submission status: Accepted

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

for i in range(n,n*10+1):
    if i>=n and len(set(map(int,str(i)))&D)==0:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, k = list(map(int, input().strip().split()))
    d = input().strip().split()
    ans = n
    while True:
        sans = str(ans)
        flag = False
        for c in sans:
            # print(c)
            # print('d ', d)
            if c in d:
                ans += 1
                flag = True
                break
        if flag:
            continue
        print(sans)
        return

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    D = LS()
    for price in range(N, 100000):
        valid = True
        for dig in D:
            if dig in str(price):
                valid = False
                break
        if valid:
            break
    print(price)

main()

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
lst = list(map(str, input().split()))
while True:
    flag = True
    for elem in list(str(N)):
        if elem in lst:
            flag = False
            break
    if flag:
        print(N)
        break
    N +=1

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(map(int, input().split()))
ok = [1] * 10
for i in d:
    ok[i] = 0

while 1:
    s = str(n)
    fin = 1
    for c in s:
        fin &= ok[int(c)]
    if fin:
        print(s)
        exit()
    n += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, D):
    D = set(map(str, D))
    i = N
    while True:
        n = [c for c in str(N)]
        if all(map(lambda x: x not in D, n)):
            return N
        N += 1



def main():
    N, K = read_int_n()
    D = read_int_n()
    print(slv(N, K, D))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while True:
    if any([c in D for c in str(N)]):
        N += 1
    else:
        print(N)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(str, input().split()))
while True:
    flg = True
    num = str(N)
    for i in range(len(num)):
        if num[i] in D:
            flg = False
            break
    if flg is True:
        print(int(num))
        break
    N += 1

Submission status: Accepted

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

N, K = [int(x) for x in input().split()]
D = [str(x) for x in input().rstrip().split()]
D = set(D)
for i in range(N, N + 10 ** 6):
    i_list = list(str(i))
    flag = 1
    for j in i_list:
        if j in D:
            flag = 0
            break
    if flag:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc042/submissions/9653489

import itertools
N, K = input().split()
P = input().split()

#使える数字
a= sorted(set([str(i) for i in range(10)])-set(P))
#同じ桁
b1 = itertools.product(a, repeat=len(N))
#繰り上がって一つ大きい桁
b2 = itertools.product(a, repeat=len(N)+1)
ans=str()
cnt=0
for i in b1:
  #print(type(i))
  ans = "".join(i)
  if N <= ans:
    print(ans)
    cnt=1
    break
if cnt==0:
  for i in b2:
    ans = "".join(i)
    #print(ans)
    if "0"+N <= ans:
      print(ans)
      break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=set(map(str,input().split()))
for i in range(n,10*n):
    num=set(list(str(i)))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

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):
    num=set(list(str(i)))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

Submission status: Accepted

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

for i in range(n,10*n):
    num=set(list(map(int,str(i))))
    if i>=n and len(D&num)==0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import itertools

N, L = map(str, input().split())
P = list(map(str, input().split()))

U = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N))
F = itertools.product(sorted(list(set([str(i) for i in range(10)])-set(P))),repeat=len(N)+1)
K = str()
cnt=0
for i in U:
	#print(''.join(i))
	K = ''.join(i)
	if int(K)>=int(N):
		cnt = 1
		print(K)
		break
#print(cnt)
if cnt == 0:
    for j in F:
        K=''.join(j)
        #print(K)
        if int(K)>=int(N):
            print(K)
            break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
hate = set(map(str, input().split()))
Nos = {str(i) for i in range(10)}
while not set(list(str(N))) & hate == set():
  N += 1
print(N)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
hate = set(map(str, input().split()))
Nos = {str(i) for i in range(10)}
available = Nos ^ hate
while not set(list(str(N))) <= available:
  N += 1
print(N)

Submission status: Accepted

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

minN = -1
for i in range(n,10*n+1):
  for j in range(len(str(i))):
    if dList.count(int(str(i)[j])) == 0:
      minN = i
    else:
      minN = -1
      break
  if minN != -1:
    break

print(minN)

Submission status: Accepted

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

Submission status: Accepted

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


    while True:
        s = set(list(str(N)))
        if len(s & D) == 0:
            print(N)
            break

        else:
            N+=1
main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = input().split()
num = set([str(i) for i in range(10)])
Ds = set(D)
diff = num^Ds
ans = N
while True:
    strN = set(list(str(ans)))
    if strN - diff:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

for i in range(N, 100000):
    str_i = str(i)
    if any([d in str_i for d in dislikes]):
        continue
    print(i)
    break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
dic={}
for i in d:
    dic[str(i)]=1
# print(dic)
# s=str(n)
# print(list(s))
while 1:
    s=str(n)
    # print(s)
    for i in range(len(s)):
        if s[i] in dic:
            break
    else:
        print(n)
        break
    n+=1

Submission status: Accepted

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

for i in range(N, 10**5):
	for c in str(i):
		if c in D:
			break
	else:
		print(i)
		exit()

Submission status: Accepted

Solution code:
nk=list(map(int,input().split()))
d=list(map(int,input().split()))
i=nk[0]
ans=0
while ans==0:
  flag=0
  for j in range(len(str(i))):
    if int(str(i)[j]) in d:
      flag=1
      break
  if flag==0:
    ans=i
  i+=1
print(ans)

Submission status: Accepted

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

while True:
    p = str(n)
    flag = True
    for c in p:
        if c in d:
            flag = False
    if flag:
        print(n)
        break
    else:
        n += 1

Submission status: Accepted

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

def ok(i):
  while i > 0:
    k = i%10
    if k in d:
      return False
    i //= 10
  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())

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

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):
  A = list(map(int, str(i)))
  flag = 1
  for a in A:
    if a in D:
      flag = 0
      break
  if flag:
    print(i)
    exit()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
for i in range(n,10*n):
    a=str(i)
    b=len(a)
    ans=True
    for j in a:
        if j in d:
            ans=False
            break 
    if ans:
        print(i)
        exit()

Submission status: Accepted

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

while True:
    flag = True
    for i in str(n):
        if i in d:
            flag = False
    if flag:
        print(n)
        exit()
    n += 1

Submission status: Accepted

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

while True:
    if set(list(str(N))) & D:
        N += 1
    else:
        print(N)
        exit()

Submission status: Accepted

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

for i in range(N, 10**5):
    for c in str(i):
        if c in D:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
E = [x for x in range(10) if x not in D]
# print(N, K, D, E)

def is_valid(n):
    while n > 0:
        d = n % 10
        if d in D:
            return False
        n //= 10
    return True

ans = N
while not is_valid(ans):
    ans += 1

print(ans)

Submission status: Accepted

Solution code:


import numpy as np
import fractions as fra



n,k=map(int,input().split())
d =[x for x in input().split()]

def che(s):#string s
    for x in s:
        for y in d:
            if(x==y):
                return 0
    return 1


for i in range(n,10**10):
    if(che(str(i))):
        print(i)
        exit(0)

Submission status: Accepted

Solution code:
import sys
from copy import copy


N, K, *D = map(int, open(0).read().split())


candidate = sorted(list({i for i in range(10)} - set(D)))
like_integer = copy(candidate)
  
# 1桁の場合を判定
for j in candidate:
  if j >= N:
    print(j)
    sys.exit()
    
for i in range(1, 6):  
  order = 10 ** i
  
  
  _candidate = []
  for l in like_integer:
    for c in candidate:
      lc = order * l + c
      if lc >= N:
        print(lc)
        sys.exit()
      _candidate.append(lc)
  candidate = _candidate

Submission status: Accepted

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

def main():
    N,K = map(int,input().split())
    D = list(map(int,input().split()))
    
    use = []
    for i in range(10):
        if i not in D:
            use.append(i)

    nl = []
    for i in range(N,10*N+1):
        num = i
        ans = True
        while num != 0:
            re = num%10
            num //= 10
            if re not in use:
                ans = False
        if ans:
            print(i)
            exit()
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def ok():
  for i in str(n):
    if int(i) in d:
      return False
  return True

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

while True:
  if ok():
    break
  n+=1

print(n)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

i = N
while 1:
    s = str(i)
    for a in A:
        if s.count(str(a)):
            break
    else:
        print(i)
        exit()
    i += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
use = [str(i) for i in range(10) if i not in d]
mon5 = [int(i+j+k+l+m) for i in use for j in use for k in use for l in use for m in use if int(i+j+k+l+m)>=n]

mon4 = [int(i+j+k+l) for i in use for j in use for k in use for l in use if int(i+j+k+l)>=n]

mon3 = [int(i+j+k) for i in use for j in use for k in use if int(i+j+k)>=n]

mon2 = [int(i+j) for i in use for j in use if int(i+j)>=n]

mon1 = [int(i) for i in use if int(i)>=n]

print(min(mon1+mon2+mon3+mon4+mon5))

Submission status: Accepted

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

set_num = set()
for i in range(10):
    set_num.add(i)

set_use_num = set_num - set_D
set_use_num = sorted(set_use_num)


for j in range(n, 88889):
    Check = True
    for num in str(j):
        if int(num) not in set_use_num:
            Check = False
    if Check:
        ans = j
        break
    else:
        continue

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ni = int(n)

f = []
while True:
	for j in range(len(d)):
		if d[j] not in n:
			f.append(True)
		else:
			f.append(False)
	if False not in f:
		break
	f = []
	ni += 1
	n = str(ni)

print(ni)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = input().split()
x = n-1
while True:
	x += 1
	s = str(x)
	f = 0
	for t in d:
		if t in s:
			f = 1
	if f == 0:
		print(x)
		break

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
for i in range(N,100000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc042/tasks/arc058_a
# 最悪でも10**6探索する程度なのでNを一つづつ足して全探索でもよくね？


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


def is_inD(n: int):
    tmp = set(str(n))
    return tmp.isdisjoint(D)


for i in range(N, N + 10 ** 6):
    if is_inD(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
### N = int(input(())
N, M = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N,100000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)

Submission status: Accepted

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

while True:
    flg=True
    for i in range(len(str(N))):
        #print(str(N)[i])
        if str(N)[i] in D:
            #print("S",str(N)[i])
            N+=1
            flg=False
            break
    if flg:
        break

print(N)

Submission status: Accepted

Solution code:
money, num = map(str, input().split())
hate = list(map(str, input().split()))

for i in range(int(money), 100000):

    a = [hate_num for hate_num in hate if hate_num in str(i)]
    if a == []:
        print(str(i))
        break

Submission status: Accepted

Solution code:
def problem_c():
    N, K = map(int, input().split())
    D = list(map(str, input().split()))
    numbers = {str(i) for i in range(10)}
    availables = set(numbers) - set(D)

    for i in range(N, 100000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return

##########
problem_c()

Submission status: Accepted

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


for i in range(N,10**9):
    flg = True
    for j in str(i):
        if j in D:
            flg = False
    if(flg):
        print(i)
        exit()

Submission status: Accepted

Solution code:
price, _ = map(int, input().split())
hate = list(input().split())

while sum([i in hate for i in list(str(price))]) > 0:
    price += 1

print(price)

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
D = [1 if i not in d else 0 for i in range(10)]
for a in range(N,10*N+1):
    for b in str(a):
        if D[int(b)] == 0:
            break
    else:
        print(a)
        break

Submission status: Accepted

Solution code:
import sys
 
input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))
sys.setrecursionlimit(10**6)

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
    
    

dfs(N)

Submission status: Accepted

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

for i in range(100001):
   yen = n + i
   if set(list(str(yen))) & set(dl):
      continue
   else:
      print(yen)
      import sys
      sys.exit()

Submission status: Accepted

Solution code:
N,K=[int(c) for c in input().split()]
D=0
for c in input().split():
  D|=(1<<int(c))
while(1):
  d=0;
  for c in str(N):
    d|=1<<int(c)
  if(d&D==0):
    print(N)
    exit()
  N+=1;

Submission status: Accepted

Solution code:
def solve(target: int, dislike_numbers: set) -> int:
    for i in range(target, target * 10):
        used_numbers = set(int(n) for n in str(i))
        if not used_numbers.intersection(dislike_numbers):
            return i

target, n = map(int, input().split())
values = map(int, input().split())
print(solve(target, set(values)))

Submission status: Accepted

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

for i in range(n, 100001):
    x = list(str(i))
    flag = True
    for j in x:
        if int(j) in a:
            continue
        else:
            flag = False
            break
    if flag is True:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import bisect
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(0,10)) ^ set(D)
length = len(str(N))

for l in range(length, length+2):
  comb = [int("".join(map(str, a))) for a in product(like_num, repeat=l)]
  ind = bisect.bisect_left(comb, N)
  if len(comb) != ind and comb[ind] >= N:
    print(comb[ind])
    exit()

Submission status: Accepted

Solution code:
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(10)) ^ set(D)
length = len(str(N))

for i in range(length, length+2):
  for x in product(like_num,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=N:
          print(d)
          exit()

Submission status: Accepted

Solution code:
import math
import fractions

n, k = map(int, input().split())
d = [i for i in input().split()]
i = n
while 1:
    flag = 1
    for j in d:
        if j in str(i):
            i += 1
            flag = 0
            break
    if flag:
        print(i)
        break

Submission status: Accepted

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

for i in range(N,10**6):
  ng = 0
  str_i = str(i)
  for s in str_i:
    if s in D:
      ng = 1
      break
  if ng == 0:
    print(i)
    break

Submission status: Accepted

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

for i in range(n,10**6+1):
    if any(x in set(str(i)) for x in d):
        continue
    else:
        print(i)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n, 10*n+1):
    num = list(str(i))
    for j, n in enumerate(num):
        if n in d:
            break
        if j == len(num)-1:
            print(i)
            exit()