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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    # print(q)

    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        # if len(b) == 0 and d == 0:
        #     pass
        # else:
        b += str(d)
        q.append(b)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N, K = MAP()
D = LIST()
 
q = deque([""])

s = set([i for i in range(0, 10)]) 
d = set(D)
kouho = s - d
kouho = sorted(list(set(kouho)))
while q:
    a = q.popleft()
    if len(a) != 0:
        if int(a) >= N:
            print(a)
            break
    for d in kouho:
        b = deepcopy(a)
        if len(b) == 0:
            if d == 0:
                continue
        b += str(d)
        q.append(b)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
a = input().split()
while True:
  if all(c not in str(n) for c in a):
    print(n)
    break
  else:
    n += 1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
dislike = list(map(str, input().split()))
num = ["0","1","2","3","4","5","6","7","8","9"]
can_use = set(num) - set(dislike)

while not set(list(str(N))) <= can_use:
    N += 1

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
	n, k, = map(int, input().split())
	ok = [str(i) for i in range(10)]
	for i in input().split():
		if i in ok:
			ok.remove(i)

	while True:
		again = False
		for i in str(n):
			if not i in ok:
				again = True
				n += 1
				break
		if not again:
			break
	print(n)
resolve()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(0,K):
    A.remove(D[i])
A=sorted(A)
B=A
B.append(0)
ans=0
M=str(N)
L=len(M)
if A[0]==0:
    ans+=111111*A[1]
else:
    ans+=111111*A[0]

if L==5:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        for y in range(0,10-K):
                            if ans>=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]>=N:
                                ans=1000*(100*B[q]+10*A[w]+A[e])+100*A[r]+10*A[t]+A[y]
elif L==4:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    for t in range(0,10-K):
                        if ans>=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]>=N:
                            ans=100*(100*B[q]+10*A[w]+A[e])+10*A[r]+A[t]
elif L==3:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                for r in range(0,10-K):
                    if ans>=10*(100*B[q]+10*A[w]+A[e])+A[r]>=N:
                        ans=10*(100*B[q]+10*A[w]+A[e])+A[r]
elif L==2:
    for q in range(0,11-K):
        for w in range(0,10-K):
            for e in range(0,10-K):
                if ans>=100*B[q]+10*A[w]+A[e]>=N:
                    ans=100*B[q]+10*A[w]+A[e]
else:
    for q in range(0,11-K):
        for w in range(0,10-K):
            if ans>=10*B[q]+A[w]>=N:
                ans=10*B[q]+A[w]

print(ans)

Submission status: Accepted

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

def checkiroha(a):
    a1 = str(a)
    for i in range(len(a1)):
        if (a1[i] in si):
            return 'F'
        elif (i == (len(a1)-1)):
            return 'T'
        else:
            continue

while (checkiroha(n) == 'F'):
    n = n+1
else:
    print(n)

Submission status: Accepted

Solution code:
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

N, K = ints()
D = [False]*10

for d in ints():
    D[d] = True

while any([D[int(d)] for d in str(N)]):
    N+=1

print(N)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Submission status: Accepted

Solution code:
def function1(m, set1):
  set2 = set(str(m))
  if len(set1 & set2) > 0:
    return False
  else:
    return True
def function(n, set1):
  m = n
  while not function1(m, set1):
    m += 1
  return m

line1 = input().split()
n = int(line1[0])
k = int(line1[1])
list1 = input().split()
set1 = set(list1)

print(function(n, set1))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(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:
def intersection(lst1, lst2): 
    lst3 = [value for value in lst1 if value in lst2] 
    return lst3 

n,k=map(int,input().split())
a=list(map(str,input().split()))
while(1):
    x=list(str(n))
    check=True
    if len(intersection(x,a))==0:
        print(n)
        break
    n+=1

Submission status: Accepted

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

i = N
while True:
  flg = True
  for j in str(i):
    if int(j) in D:
      flg = False
      break

  if flg == True:
    print(i)
    exit()

  i += 1

Submission status: Accepted

Solution code:
def check(n):
    if set(list(map(int, str(n)))) & D:
        return 1
    else:
        return 0


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

surplus = 0
while check(N + surplus):
    surplus += 1
print(N + surplus)

Submission status: Accepted

Solution code:
n, k=map(int, input().split())
d = list(input().split())
i=n
while True:
    count = 0
    for j in range(k):
        if d[j] in str(i):
            count += 1
    if count == 0:
        print(i)
        break
    else:
        i += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
N, K = map(int, input().split())
# 文字列用のリスト　インプットをブランクで区切りリスト化
k = input()
s = [int(j) for j in k.split(" ")]
valIn = 0
# Nの桁毎の分解
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

def irohacheck(n):
	global valIn
	valIn = 0
	# 分解した数値をリストにして格納
	num = digit(n)
	# num内の数字がsに含まれる場合には、valInをインクリメント
	for i in range(len(num)):
		if s.count(num[i])>0:
			valIn+=1

irohacheck(N)
while(valIn != 0):
	N += 1
	irohacheck(N)
print(N)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
d = list(input().split())
for check in range(n, 10 ** 5):
    flag = True
    for i in str(check):
        if i in d:
            flag = False
            break
    if flag:
        print(check)
        exit()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = input().rstrip().split()

    for i in range(n, 10**8):
        s = str(i)
        for j in a:
            if j in s:
                break
        else:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def resolve():
    N, K = map(int, input().split())
    D = set(input().split())
    while True:
        if D & set(str(N)):
            N += 1
            continue
        print(N)
        return


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def is_include(n,D):
  for c in str(n):
    for d in D:
      if d == c:
        return True
  else:
    return False

n,k = map(int,input().split())
D = list(map(str,input().split()))
for i in range(n,n*10):  
  if is_include(i,D) == False:
    print(i)
    break

Submission status: Accepted

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

nmax=100000

for nn in range(n,nmax):
    ns=list(str(nn))
    yn="yes"
    for nsi in ns:
#        print(nn,nsi,(nsi in d))
        if int(nsi) in d:
            yn="no"
            break
    if yn=="no":
        continue
    else:
        break
if yn=="yes":
    print(nn)

Submission status: Accepted

Solution code:
import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)

def main(d):
    res = ''
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    j = str(j)
                    if j in d:
                        res += j
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l
    print(res)

if __name__ ==  '__main__':
    main(d)

Submission status: Accepted

Solution code:
import sys
from string import digits

n, k, *d = sys.stdin.read().split()
d = set(digits) - set(d)
l = len(n)

def main(d):
    res = ''
    flag = True
    for i in range(l):
        if flag:
            if n[i] in d:
                res += n[i]
            else:
                flag = False
                for j in range(int(n[i]), 10):
                    if str(j) in d:
                        res += str(j)
                        break
                else:
                    break
        else:
            res += min(d)
    else:
        print(res)
        return
    d = sorted(d)
    res = d[0] * (l + 1) if d[0] != '0' else d[1] + '0' * l
    print(res)

if __name__ ==  '__main__':
    main(d)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
D = set(list(map(str,input().split())))
while True:
    s = set(list(str(n)))
    if len(s&D)==0:
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:

import collections


def solve(n, k, digits):
    digitsNotAvailable = set(digits)

    ans = n

    while True:
        temp = ans
        possible = True

        while temp:
            digit = temp % 10

            if digit in digitsNotAvailable:
                possible = False
                break

            temp //= 10

        if possible:
            return ans

        ans += 1

    return None


[n, k] = list(map(int, input().strip().split()))
digits = list(map(int, input().strip().split()))

print(solve(n, k, digits))

Submission status: Accepted

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

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

kagu = []

for i in range(10):
    if i in t:
        continue
    kagu.append(str(i))

ans = 1000000000000

for i in kagu:
    if i == '0':
        continue
    if n<=int(i):
        print(i)
        exit()
    memo = [i]
    while int(memo[-1])< n:
        a = memo.pop(0)
        for j in kagu:
            goukei = a+j
            memo.append(goukei)
            if n<=int(goukei):
                ans = min(ans,int(goukei))
                break
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

        L={i for i in range(10)}
        U=L-D
        while True:

            sn = str(N)
            ln = len(sn)

            for i in range(ln):
                if int(sn[i]) not in U:
                    N+=1
                    break
                elif i==ln-1:
                    return int(N)
    print(main())



resolve()

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
d = LI()
for i in range(n,10*n+1):
    s = Counter(list(map(int,list(str(i)))))
    for j in d:
        if s[j] > 0:
            break
    else:
        print(i)
        quit()

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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

def main():
  n,k = readInts()
  D = input().split()
  #print(D)
  #print(list(str(now)))
  #print(set(str(n)) & set(D))
  
  #print({'2','5'} & {'2'})
  while set(str(n)) & set(D):
    n += 1
  print(n)
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N,K = list(map(int,input().split()))
D = list(map(str,input().split()))
D = set(D)
# print(D)
i = N
while True:
    # print("i =",i)
    b = list(str(i))
    b = set(b)
    # print(b)
    c = b&D
    # print(c)
    if len(c)>0 :
        i += 1
        continue
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = list(input().split())
dis = False
while True:
  a = str(n)
  hate = False
  for x in a:
    for y in d:
      if x == y:
        hate = True
        break
    if hate == True:
      break
  if hate == True:
    n += 1
  else:
    break
  if n > 100000:
    break
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

    S={i for i in range(10)}
    D=set(map(int,input().split()))
    D=S-D

    def search(N):
        for i in range(len(N)):
            if int(N[i]) not in D:
                return True
            elif i==len(N)-1:
                return False

    while True:
        if search(N) ==True:
            N=str(int(N)+1)
        else:
            print(N)
            break









resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# 全探索
n,k = map(int,input().split())
s = str(n)
d = list(map(int,input().split()))
for i in range(n,100000):
    # i の中にd に含めれるものがないか１つづつ見ていく
    str_i = str(i)
    ok = 1
    for j in str_i:
        if int(j) in d:
            ok = 0
            break
    if ok:
        print(i)
        exit()

Submission status: Accepted

Solution code:
ans,k = map(int,input().split())
d = set(input().split())
f = True
while f:
    f = False
    for i in str(ans):
        if i in d:
            f = True
    if f:ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,K=input().split()
nums = input().split()
cand = list(map(str,list(x for x in range(10))))
for num in nums:
  if num in cand:
    cand.remove(num)
work = []
if int(N) <= int(cand[-1]*len(N)):
  for i in range(len(N)):
    for c in cand:
      if int(N[i]) == int(c):
        work.append(c)
        break
      elif int(N[i]) < int(c):
        work.append(c)
        for j in range(i+1,len(N)):
          work.append(cand[0])
        print(''.join(work))
        exit()
else:
  if cand[0] != '0':
    work.append(cand[0])
  else:
    work.append(cand[1])
  for i in range(len(N)):
    work.append(cand[0])
print(''.join(work))

Submission status: Accepted

Solution code:
import sys

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

for i in range(n,1000000000):
  for j in range(len(str(i))):
    if str(i)[j] in str(d):
      break
      
    else:
      count+=1
      
  if count==len(str(i)):
    print(i)
    sys.exit()
  count=0

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

N,K=map(int,input().split())
D=list(map(int,input().split()))
like=list(range(1,10))
dislike0=False

for s in D:
    if s==0:
        dislike0=True
    else:
        like.remove(s)

like.sort()
q=deque(like)

if dislike0==False:
    like.insert(0,0)

while q:
    num=q.popleft()

    if num>=N:
        print(num)
        exit()
    for i in range(len(like)):
        q.append((int(str(num)+str(like[i]))))

Submission status: Accepted

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

n_str = str(n)
# print(n_str)

l = list(({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(d)))

# print(l)

ans = n
found = False
while not found:
  found = True
  ans_str = str(ans)
  for i in range(len(ans_str)):
    if int(ans_str[i]) not in l:
      # print("NOT FOUND", ans_str[i])
      found = False
  ans +=1

ans -= 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8-*-
strs = []
n,k = map(int,input().split())
hates = list(input().split())

give = n

while(True):
  stri = str(give)
  hantei = True
  for hate in hates:
    if hate in stri:
      hantei = False
      break;
  if hantei:
    print(give)
    break;
  else:
    give = give + 1

Submission status: Accepted

Solution code:
import itertools
n,k = map(int,input().split())
unlike = list(map(int,input().split()))
like = []
for i in range(0,10):
    if not(i in unlike):
        like.append(i)
i = 1
ans = 0
while(i < 99):
    current = list(itertools.product(like,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if n <= h:
            print(h)
            exit()
    i += 1

Submission status: Accepted

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

n=[str(N)[i] for i in range(len(str(N)))]
#print(n)
for i in range(N,10*N+1):
  flag=True
  for j in range(len(str(i))):
    if(int(str(i)[j]) in D):
      flag=False
  if(flag==True):
    ans=i
    break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def checkN(N,D):
    for each in N:
        if each in D:
            return False
    return True
line1 = input().split(' ')
N = line1[0]
D = input().split(' ')
i = -1
while not checkN(N, D):
    N = str(int(N)+1)
    # i -= 
print(N)

Submission status: Accepted

Solution code:
def solve(price, usable):
  ans = price
  usable_set = set(usable)
  while True:
    ans_set = {int(i) for i in list(str(ans))}
    if ans_set <= usable_set:
      return ans
    ans += 1

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

  usable = [int(i) for i in range(10) if i not in d_list]
  print(solve(n, usable))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def judge(strn):
    for i in strn:
        if i in d: return 0
        else: continue
    return 1

while True:
    strn = str(n)
    if judge(strn): 
        print(strn)
        exit()
    else: n+=1

Submission status: Accepted

Solution code:
N,_=map(int, input().split())
D=input().rstrip().split()
n=N
while True:
	flag=False
	s=list(str(n))
	for i in s:
		if i in D:
			flag= True
			break
	if not flag:
		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, 100000):
    if not set(list(str(i))) & D:
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(1,100001):
    if i<n:
        continue
    num=str(i)
    ok=True
    for nn in num:
        if int(nn) in d:
            ok=False
            break
    if ok:
        print(i)
        exit(0)

Submission status: Accepted

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

import re 
L=[0,1,2,3,4,5,6,7,8,9]
D=set(D)
L=set(L)
L_D =list(L-D)

while True:
    Value=N
    S_value=str(Value)
    for j in range(len(L_D)):
        S_value=re.sub('{}'.format(L_D[j]),'',S_value)
    if S_value=='':
        print('{}'.format(Value))
        exit(0)
    N+=1

Submission status: Accepted

Solution code:
n,k,*d=map(int,open(0).read().split())
while 1:
 for i in str(n):
  if int(i)in d: break
 else:print(n);break
 n+=1

Submission status: Accepted

Solution code:
n=int(input().split()[0]);d=set(input());print(min(i for i in range(n,99999)if not d&set(str(i))))

Submission status: Accepted

Solution code:
n = int(input().split()[0])
d = set(input())
for i in range(n, 999999):
    if not set(str(i)) & d:
        print(i)
        break

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = list(input())
a = set(a)
for ans in range(n,n+100000):
    tmp = str(ans)
    for i,t in enumerate(tmp):
        if t in a:
            break
    else:
        print(ans)
        break

Submission status: Accepted

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

Submission status: Accepted

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

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)

Submission status: Accepted

Solution code:
amount, num_cnt = map(int, input().split())
hate_list = input().split()

payment = 0
for i in range(amount, 100000):
    nums = set(list(str(i)))
    flg = False
    for j in nums:
        if j in hate_list:
            flg = True
            break
    if not flg:
        payment = i
        break

print(payment)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))
possible=set()
for i in range(0,10):
    if i not in d:
        possible.add(str(i))
for i in range(n,100000):
    i=str(i)
    for j in i:
        if j not in possible:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
d = list(map(int,input().split()))
def ok(x):
    x = str(x)
    for i in range(len(x)):
        if int(x[i]) in d:
            return False
    return True
for i in range(n,10**5):
    if ok(i):
        print(i)
        break

Submission status: Accepted

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

def valid(x):
    for xx in str(x):
        if int(xx) in D:
            return False
    return True

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

Submission status: Accepted

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

for i in range(10 ** 6):
    S = set(list(str(N)))
    if not D & S:
        break
    N += 1

print(N)

Submission status: Accepted

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

for k in range(N, 20 * N):
    if len(set(list(str(k))) & D) == 0:
        print(k)
        exit()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, k = MAP()
d = LIST()
for i in range(n, n * 10):
    y = list(str(i))
    flag = True
    for j in d:
        if str(j) in y:
            flag = False
            break
    if flag:
        print(i)
        exit()

Submission status: Accepted

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

def check(x):
    for c in str(x):
        if c in D: return False
    return True

ans = N
while not check(ans): ans += 1
print(ans)

Submission status: Accepted

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

for i in range(100001):
    S = set(list(str(N)))
    if not A & S:
        ans = N
        break
    N += 1

print(N)

Submission status: Accepted

Solution code:
def solve():
    n,k = map(int,input().split())
    d = set(map(int,input().split()))
    for i in range(n,100000):
        s = map(int,str(i))
        flag = True
        for j in s:
            if j in d:
                flag = False
        if flag:
            print(i)
            return

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
d = set(map(int, input().split()))
for x in range(N, 10 ** 6):
  f = 1
  for y in str(x):
    if int(y) in d:
      f = 0
      break
  if f:
    print(x)
    exit(0)

Submission status: Accepted

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

while True:
    res = str(N)
    for v in D:
        if v in res:
            break
    else:
        print(res)
        quit()
    N += 1

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    D = {i for i in input().split()}
    ans = N
    while any(a in D for a in str(ans)):
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()