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:
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

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

d = list(map(int, input().split()))
a = []
for i in range(10):
  if i not in d:
    a.append(str(i))
ans = n
while True:
  b = str(ans)
  if all([i in a for i in b]):
    break
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
arr = list(input().split())
ans = 0
for i in range(N,10**7):
    flg = True
    s = str(i)
    for k in s:
        if str(k) in arr:
            flg = False
            break
    if flg:
        print(i)
        exit()

Submission status: Accepted

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

while any(int(x) in d for x in str(n)):
  n += 1
print(n)

Submission status: Accepted

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

while any(int(x) in d for x in str(n)):
    n += 1

print(n)

Submission status: Accepted

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

d = set([str(_d) for _d in d])

ans = n
while True:
    f = True
    a = str(ans)
    for _a in a:
        if _a in d:
            f = False
    if f:
        print(ans)
        break
    else:
        ans += 1

Submission status: Accepted

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

num = list(map(str, range(10)))
for k in range(K):
  num.remove(D[k])
for I in range(N, 100000):
  if all([II in num for II in str(I)]):
    print(I)
    break

Submission status: Accepted

Solution code:
n, k = input().split(' ')
d = list(input().split(' '))
while any(x in d for x in n):
    n = str(int(n) + 1)
print(n)

Submission status: Accepted

Solution code:
n, k = input().split(' ')
d = list(input().split(' '))
while any(x in d for x in n):
    n = str(int(n) + 1)
print(n)

Submission status: Accepted

Solution code:
import sys
N, K = map(int, input().split())
st = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
dis = map(int, input().split())
for i in dis:
    st.remove(i)


def dfs(num, pos, target):
    if pos == target:
        if num >= N:
            print(num)
            sys.exit()
        return
    for i in st:
        dfs(num * 10 + i, pos + 1, target)


Len = len(str(N))
dfs(0, 0, Len)
dfs(0, 0, Len+1)

Submission status: Accepted

Solution code:
ip = input().split()
N = int(ip[0])

K = int(ip[1])
Dinput = input().split()
Ds = []#嫌いな数
for i in range(K):
    Ds.append(Dinput[i])#文字列

boolean = False
n = N
while boolean == False:
    str_n = list(str(n))
    for d in range(K):
        if Ds[d] in str_n:#嫌いな文字がある場合
            boolean = False
            break
        else:
            boolean = True
    if boolean == False:
        n += 1
    
print(n)

Submission status: Accepted

Solution code:
n,k = list(map(int,input().split()))
l = list(map(str,input().split()))
while set(str(n))&set(l):n+=1
print(n)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

while True:
	for s in str(N):
		if A.count(int(s)): break
	else:
		break
	N += 1
print(N)

Submission status: Accepted

Solution code:
n,a =map(int,input().split())
s=list(map(str,input().split()))
while set(str(n))&set(s):
    n+=1
print(n)

Submission status: Accepted

Solution code:
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int,input().split())
    D = set(list(input().split()))
    for k in range(N,100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

while set(str(n)) & d:
    n += 1

print(n)

Submission status: Accepted

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

n = N
while True:
    s = str(n)
    S = set(list(s))
    for c in S:
        if c in D:
            break
    else:
        break
    n += 1
print(n)

Submission status: Accepted

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

def isAvailable(x):
    for c in str(x):
        if int(c) in d:
            return False
    return True

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

Submission status: Accepted

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

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

print(n)

Submission status: Accepted

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

payment = n
while True:
    tmp = str(payment)
    for t in tmp:
        if t in dislikes:
            break
    else:
        break
    payment += 1
print(payment)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
T=list(map(int,input().split()))
#N=9999 
#M=1
#T=[1,3,4,5,6,7,8,9]
#T=[]
L=[]
for i in range(10):
    if(not T.count(i)):
        L.append(i)

l=len(str(N))+1
MIN=10**10

def calc(st):
    global MIN
    st=str(st)
    if(len(st)>l):return 0
    for num in L:
        t=calc(st+str(num))
        if(int(t)>=N):
            MIN=min(MIN,int(t))
    if(st!=""):
        if(int(st)>=N):
            MIN=min(int(st),MIN)
    return (MIN)

print(calc(str()))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
D = set(LI())
for i in range(n, 100000):
    if not set([int(j) for j in str(i)]) & D:
        print(i)
        break

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
D = set(range(10)) - set(LI())
for i in range(n, 100000):
    if set([int(j) for j in str(i)]) <= D:
        print(i)
        break

Submission status: Accepted

Solution code:
from itertools import *

if __name__=="__main__":
    n,k = map(int,input().split(' '))
    d = list(map(int,(input().split(' '))))
    d = [i for i in range(10) if i not in d]
    ans = 1e10
    keta = len(str(n))
    for k in range(1,keta+2):
        for perm in product(d,repeat=k):
            num = 0
            for v in perm:
                num = 10*num+v
            if n <= num and num < ans:
                ans = num
    print(ans)

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for v in list(map(int, input().rstrip('\n').split())):
        d[str(v)]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for v in s:
            if v in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools
n, k = map(int, input().split())
d = set(list(map(int, input().split())))
inzero = False
if 0 in d:
    inzero = True
    d -= set([0])
can_use = set([0,1,2,3,4,5,6,7,8,9]) - d
can_use = list(can_use)
#全探索
ans = 10**6
def check(i):
    global ans
    x = int("".join(list(map(str, i))))
    if inzero:
       pp = list(str(x))
       if '0' in pp:
           return
    if x >= n:
        ans = min(ans, x)
def dfs(Sequence):
    if len(Sequence) == len(str(n)) + 1:
        check(Sequence)
    else:
        for i in can_use:
            dfs(Sequence + [i])
dfs([])
print(ans)

Submission status: Accepted

Solution code:
import sys

n, k, *dislikes = sys.stdin.read().split()
n = int(n)
dislikes = set(dislikes)

def main():
    i = n
    while True:
        if set(str(i)) & dislikes:
            i += 1
            continue
        return i

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys
from string import digits
from itertools import product
from bisect import bisect_left as bi_l

n, k, *dislikes = sys.stdin.read().split()

def main():
    likes = sorted(set(digits) - set(dislikes))
    cand = product(likes, repeat=len(n))
    *cand, = map(lambda x: int(''.join(x)), cand)
    cand.sort()
    res = bi_l(cand, int(n))
    if res < len(likes) ** len(n):
        return cand[res]
    
    if likes[0] == '0':
        ans = likes[1] + '0' * len(n)
    else:
        ans = likes[0] * (len(n)+1)
    return int(ans)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

p = n
while any(de in str(p) for de in d):
    p += 1
print(p)

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))
    ok_set = set([i for i in range(0,10)]) - D
    ok_list = list(ok_set)
    # print(ok_list)

    def is_ok(num):
        ans = True
        for si in str(num):
            n = int(si)
            if n not in ok_list:
                ans = False
        return ans

    for ni in range(N, 10 ** 9):
        if is_ok(ni):
            print(ni)
            break



if __name__ == "__main__":
    main()

Submission status: Accepted

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

    OK_N = set([i for i in range(0, 10)]) - D
    OK_N = list(OK_N)

    l1 = [str(i)for i in OK_N]
    for _ in range(len(str(N)) - 1):
        tmp_l = []
        for li in l1:
            # print(li)
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l1 = tmp_l

    l2 = [str(i)for i in OK_N]
    for _ in range(len(str(N))):
        tmp_l = []
        for li in l2:
            # print(li)
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l2 = tmp_l

    lc = []
    for li in l1:
        lc.append(int(li))
    for li in l2:
        lc.append(int(li))
    # print(lc)

    lc.sort()
    for li in lc:
        if li >= N:
            print(li)
            break

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in product(nm,repeat=5):
  b.append(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4])
  b.append(1000*i[0]+100*i[1]+10*i[2]+i[3])
  b.append(100*i[0]+10*i[1]+i[2])
  b.append(10*i[0]+i[1])
  b.append(i[0])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Submission status: Accepted

Solution code:
from bisect import bisect_left
from itertools import product
N, K = map(int, input().split())
D = [int(i) for i in input().split()]
ary = []
for n in range(10):
    if n not in D:
        ary.append(str(n))

l = []
for it in product(ary, repeat=len(str(N))):
    n = int(''.join(it))
    l.append(n)
    if n > 10000:
        break
l.sort()
i = bisect_left(l, N)
if i < len(l):
    print(l[i])
else:
    print(int((ary[0] if ary[0] != '0' else ary[1]) + ary[0]*(len(str(N)))))

Submission status: Accepted

Solution code:
def iroha(n):
    flag = False
    tmp = list(map(int, list(set(list(str(n))))))
    for i in tmp:
        if D.count(i) != 0:
            return flag
    flag = True
    return flag


N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    if iroha(N):
        break
    N += 1
print(N)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = set(input().split())
while 1:
    E = set(str(N))
    if not(D&E):
        print(N)
        break
    N+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N  ,K = map(int,input().split())
D = list(input())
now = N
s = set(list(str(now)))
d = set(D)
while s & d != set():
    now += 1
    #print(now)
    s = set(list(str(now)))
print(now)

Submission status: Accepted

Solution code:
import sys
N,K,*vD=map(int,sys.stdin.buffer.read().split())
for x in range(N,10**5):
	if any(int(d) in vD for d in str(x)):
		continue
	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,1000000):
    f=1
    for k in d:
        if str(k) in str(i):
            f=0
            break
    if f:
        print(i)
        exit()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(input())
for i in range(N,10**5):
    si = str(i)
    f = True
    for digit in si:
        if digit in D:
            f = False
            continue
    if f:
        print(i)
        exit()

Submission status: Accepted

Solution code:
# 購入する数字N
# 嫌いな数字の個数K
N,K = map(int,input().split())

# 嫌いな数字をリストに入力
D = input().split()

# Lから1づつ増やしていき、嫌いな数字が含まれていない事をチェックする
# 最大計算量はNの10倍
# N=9999のときは、9999から99999まで計算すれば良い
for n in range(N,10*N):
    # 数字nを一度文字列にする
    # setを使ってnとDを集合の要素にする
    # isdisjointは集合同士を比較して、
    # 要素が1つもかぶらなければTrueを返す
    if set(str(n)).isdisjoint(set(D)):
        print(n)
        # 1個見つかったら終了
        break

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
s = list(map(str,input().split()))
num=int(a)
D = set(s)
numbers = {str(i) for i in range(10)}
available = numbers - D

for i in range(a,100000):
  nums = set(str(i))
  if nums <= available:
    print(i)
    break

Submission status: Accepted

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

# l = N, r = N * 10
for i in range(N, N * 10 + 1):
    if not any([s in D for s in str(i)]):
        print(i)
        exit()
print('err')

Submission status: Accepted

Solution code:
N, K = input().split()
K = int(K)
NL = list(map(int, N[::-1]))

D = [int(_) for _ in input().split()]

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

mod_idx = -1
i = 0
while len(NL) > i:
    n = NL[i]
    for j in range(n, 10):
        if j in D:
            NL[i] += 1
            mod_idx = i
        else:
            break

    if NL[i] >= 10:
        if i + 1 >= len(NL):
            NL.append(0)
        NL[i + 1] += 1
        mod_idx = i + 1
    i += 1

if mod_idx >= 0:
    for i in range(0, mod_idx):
        NL[i] = min_d
print(*reversed(NL), sep='')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
Dset = set(input().split())
while True:
    if Dset & set(str(N)) == set():
        print(N)
        break
    else:
        N += 1

Submission status: Accepted

Solution code:
import sys

def hantei(array,n):
  s = str(n)
  for i in range(len(s)):
    if int(s[i]) in array:
      return False
  
  return True

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

while True:
  if hantei(d,n):
    print(n)
    sys.exit()
    
  n += 1

Submission status: Accepted

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

for i in range(n,100000):
    f=0
    for j in d:
        if str(i).find(j) >= 0:
            break
        else:
            f+=1
    if f == k:
        print(i)
        sys.exit()

Submission status: Accepted

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

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in range(N, 100000):
    a=i//10000
    if bool((a not in D) or i <10000):
        b=i//1000 - 10*a
        if bool((b not in D) or i <1000):
            c=i//100 - 100 * a - 10 * b
            if bool((c not in D) or i < 100):
                d= i//10 - 1000 * a - 100*b - 10*c
                if bool((d not in D) or i <10):
                    e=i%10
                    if e not in D:
                        ans.append(i)
print(ans[0])

Submission status: Accepted

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

ans = n
while 1:
    a = str(ans)
    count = 0
    for i in range(len(a)):
        if a[i:i+1] in d:
            count += 1
    if count == 0:
        break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, _ = input().split(' ')
N = int(N)

dislikes = input().split(' ')


while True:
    n_str = str(N)
    if not any([n in dislikes for n in n_str]):
        print(n_str)
        break
    N += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(str,stdin.readline().rstrip().split()))

for i in range(n,99999):
    yen = str(i)
    frag = 0
    for j in yen:
        if j in li:
            frag = 1
    if frag == 0:
        print(yen)
        exit()

Submission status: Accepted

Solution code:
import sys

n, k = map(int, input().split())
d = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}-set(int(x) for x in input().split()))

while True:
  ans = n
  while ans > 0:
    key = ans%10
    if key in d:
      ans = ans//10
      if ans == 0:
        print(n)
        sys.exit()
      continue
    else:
      break
  n += 1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
while 1:
  hantei=0
  for i in range(len(str(n))): 
    #print(str(n)[i])
    if int(str(n)[i]) in d: #1つでも嫌いな数字がある場合はその瞬間判定1にして次の数へ
      hantei=1
      break
  if hantei==0: #嫌いな数字がない場合はその数字が正解なのでbreak
    break
  n+=1
print(n)

Submission status: Accepted

Solution code:
NLinput = input()
NLinput = [int(x) for x in NLinput.split()]

N = NLinput[0]
L = NLinput[1]
input_D = input()
D_list = set([int(x) for x in input_D.split()])

bill = N
flag = True

while flag:
    temp = set([int(x) for x in list(str(bill))])
    if len(list(temp&D_list))==0:
        flag = False
    else:
        bill += 1
print(bill)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    D=set(map(int,input().split()))
    for i in range(n,100000):
        flag=True
        for s in str(i):
            if(int(s) in D):
                flag=False
        if(flag):
            print(i)
            return
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

while len(d.intersection(set(list(str(n)))))>0:
    n+=1

print(n)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
l=set(input().split())
while True:
    if set(str(n)) & l == set():
        print(n)
        exit()
    n+=1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
L = set(input().split())
while True:
  if set(str(n)) & L == set():
    print(n)
    exit()
  n += 1

Submission status: Accepted

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

Submission status: Accepted

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

while(True):
    if(not({int(c) for c in str(n)} & d)):
        break
    n += 1

print(n)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
#str 注意
def main():
    n,k = map(int,input().split())
    d = [x for x in input().split()]
    d = set(d)

    while 1:
        if len(set(list(str(n))) & d)==0:
            print(n)
            exit()
        else:
            n +=1

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
nums = input().split()
s_N = str(nums[0])
i_N = int(nums[0])
K = int(nums[1])
nums2 = input().split()
count = 0

while count < K:
    #x=嫌いな数候補
    x = nums2[count]
    if x in s_N:
        i_N += 1
        s_N = str(i_N)
        count = 0
    else:
        count += 1

print(s_N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n,k=map(int,input().split())
D=set(input().split())
while True:
    ns=str(n)
    for ni in ns:
        if ni in D:
            break
    else:
        print(n)
        exit()
    n+=1
    continue

Submission status: Accepted

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

while 1:

    strN=str(N)
    flag=0
    for n in range(len(strN)):
        if strN[n] in D:
            flag=1
            break
    if flag:
        N+=1
    else:
        print(N)
        exit()

Submission status: Accepted

Solution code:
import string
n,k =[int(i) for i in input().split()]
not_use=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in not_use]

def check(n):
    for i in str(n):
        if(int(i) in not_use):
            return False
    return True


x=n-1
while True:
    x+=1
    if(check(x)==True):
        print(x)
        exit()

Submission status: Accepted

Solution code:
NK=input().split()
N=int(NK[0])
K=int(NK[1])
D=input().split()

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

Submission status: Accepted

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

for i in range(N*10):
    if i >= N:
        s = str(i)
        for j in s:
            if int(j) in D:
                break
        else:
            print(s)
            break

Submission status: Accepted

Solution code:
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0] for _ in range(prv_len-i)]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i:] = [nums[j]] + [nums[0] for _ in range(len(N)-i-1)]
  #print(i,N)
  i -= 1
print(''.join([str(n) for n in N]))
#print(N)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N):
    if i >= N:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in D:
          break
      else:
        print(i)
        return 0
solve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
D=list(map(int,input().split()))
L=D
for i in range(9*n):
    for s in str(n+i):
        if int(s) in D:
            break
    else:
        print(n+i)
        exit()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0
 
solve()

Submission status: Accepted

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

for i in range(N,100000):
  j=0
  si=list(str(i))
  for k in si:
    if int(k) in D:
      j=1
  if j==0:
    print(i)
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
d = list(input().split())
ans = n
while True:
    flag = False
    a = list(str(ans))
    for dx in d:
        if dx in a:
            flag = True
    if flag:
        ans +=1
    else:
        print(ans)
        exit()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    D = list(str(x) for x in input().split())

    while True:
        strN = str(N)
        flg = 0
        for i in strN:
            if i in D:
                flg = 1
        if flg == 0:
            print(N)
            break
        else:
            N += 1
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,88889):
    if use >= set(str(i)):
        print(i)
        break

Submission status: Accepted

Solution code:
N,K = [int(i) for i in input().split()]
#D = [int(i) for i in input().split()]は数値代入
#文字列を複数代入
D = input().split()
#集合に置き換える(型はset)
D = set(D)
use = set(['0','1','2','3','4','5','6','7','8','9'])
use -= D

for i in range(N,100*N):
    if use >= set(str(i)):
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
x=list(range(1,100000)[::-1])
for i in d:
  a=[]
  for j in x:
    if i not in str(j):
      a.append(j)
  x=a
import bisect as bi
x=x[::-1]
print(x[bi.bisect_left(x,n)])

Submission status: Accepted

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

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if test(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)

Submission status: Accepted

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

while True:
    l = list(str(N))
    for x in l:
        if x in D:
            N += 1
            break
    else:
        print(N)
        exit()

Submission status: Accepted

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

for i in range(n, 100001):
    flag = True
    for j in str(i):
        if j in d:
            flag = False

    if flag:
        print(i)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, k = [int(item) for item in input().split()]
d = [item for item in input().split()]
for i in range(n, n+10**5):
    si = str(i)
    ok = True
    for item in d:
        if item in si:
            ok = False
            break
    if ok:
        print(i)
        exit()