Problem:


Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.

She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

Input

The input is given from Standard Input in the following format:

N K
D_1 D_2 … D_K

Output

Print the amount of money that Iroha will hand to the cashier.

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

Sample Input 2

9999 1
0

Sample Output 2

9999



Sample input:
1000 8
1 3 4 5 6 7 8 9


Sample output:
2000

Submission status: Accepted

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

    for i in range(10):
        if i not in D:
            min_ = i
            break

    ans = []
    apnd = ans.append
    num, top, i = N, 0, 0
    while num > 0:
        while num % 10 in D:
            num += 1
            top = i
        num, m = divmod(num, 10)
        apnd(m)
        i += 1

    ans[0:top] = [min_] * top
    print(*ans[::-1], sep='')

main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
hate = list(map(int, input().split(' ')))
allow = set([0,1,2,3,4,5,6,7,8,9]) - set(hate)
for i in range(N, 88889):
    tmp_set = set(map(int, list(str(i))))
    if tmp_set <= allow:
        print(i)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

D = [i for i in input().split()]
c = n

def match(A,B):
    for a in A:
        if a in B:
            return True
    else:
        return False
        
while True:
    if match(D,list(str(c))):
        c += 1
        continue
    else:
        break
    
    
print(c)

Submission status: Accepted

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

while True:
    if set(str(n)).intersection(o):
        n += 1
    else:
        break
print(n)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
s=list(input().split())
q=1
while q==1:
    for i in list(str(N)):
        if i in s:
            N=N+1
            break
    else:
        print(N)
        q=0

Submission status: Accepted

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

Submission status: Accepted

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

while True:
    if not set(str(n)) & d:
        break
    n += 1

print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                elif 0 in [k,l,m] and k != 0:
                                    continue
                                elif 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)
#print(n_oks)

def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                if 0 in [k,l,m] and k != 0:
                                    continue
                                if 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=[]
R=[]
if N>=1000:
    L=list(itertools.product(S,S,S,S))
    R=sorted([int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L])
elif N>=100:
    L=list(itertools.product(S,S,S))
    R=sorted([int(str(i[0])+str(i[1])+str(i[2])) for i in L])
elif N>=10:
    L=list(itertools.product(S,S))
    R=sorted([int(str(i[0])+str(i[1])) for i in L])
else:
    L=list(itertools.product(S))
    R=sorted([int(str(i[0])) for i in L])
P=len(str(N))
for i in R:
    if int(i)>=N:
        print(i)
        exit()
if S[0]!=0:
    print(str(S[0])*(P+1))
else:
    print(str(S[1])+"0"*P)

Submission status: Accepted

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

INPUT = input()
N = int(INPUT.split()[0])
# N_list = [int(x) for x in list(str(N))]
# K = int(INPUT.split()[1])
D_list = map(int, input().split())

DIGITS = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
# usable_digits = list(DIGITS - set(D_list))
usable_digits = DIGITS - set(D_list)

while True:
    N_set = set([int(x) for x in list(str(N))])
    if N_set <= usable_digits:
        break
    N += 1

print(N)

Submission status: Accepted

Solution code:
l = list(map(int,input().split()))
n = l[0]
k = l[1]
d = list(map(int,input().split()))

n_str = list(str(n))
can_use = []
for i in range(10):
    can_use.append(i)
    
for j in d:
    can_use.remove(j)


for i in range(len(n_str)):
    j = int(n_str[i])
    n_str[i] = j
    

ss = []

for i in range(n * 10 + 1):
    ss.append(n + i)

aaa = 0

for j in ss:
    jl = list(str(j))
    for k in range(len(jl)):
        m = int(jl[k])
        jl[k] = m
    if set(jl) <= set(can_use):
        aaa = jl
        break

bbb = ''
for i in aaa:
    bbb = bbb + str(i)
    
print(int(bbb))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
nums = [i for i in range(10) if not i in l]

while True:
  total = 0
  for num in nums:
    total += list(str(n)).count(str(num))
  
  if total == len(list(str(n))):
    print(n)
    break
  
  n += 1

Submission status: Accepted

Solution code:

input_array = list(map(int,input().split()))
N = input_array[0]
input_array = list(map(int,input().split()))

num = [1,1,1,1,1,1,1,1,1,1]
ok = []
out = []

for l in range(len(input_array)):
    num[input_array[l]] = 0

for i in range(len(num)):
    if num[i] == 0:
        ok.append(i)

while True:
    key = 0
    for n in list(str(N)):
        if int (n) in ok:
            key += 1
    if key == 0:
        print(N)
        break
    else:
        N+=1

Submission status: Accepted

Solution code:
n,k = (int(i) for i in input().split())
d = [int(i) for i in input().split()]
for i in range(n,88889):
	a = str(i)
	if all(int(j) not in d for j in a):
		print(i)
		break

Submission status: Accepted

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

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


minvalue=N
temp=0

for i in range(10*N):
    i=i+N
    numtemp=i
    if numtemp>=10000:
        num_4=int(i/10000)
        i=i-10000*num_4
    else:
        num_4=10
        
    if numtemp>=1000:
        num_3=int(i/1000)
        i=i-1000*num_3
    else:
        num_3=10
        
    if numtemp>=100:
        num_2=int(i/100)
        i=i-100*num_2
    else:
        num_2=10
        
    if numtemp>=10:
        num_1=int(i/10)
        i=i-10*num_1
    else:
        num_1=10
        
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
            temp+=1
            
    if temp==K:
        num=numtemp
        break
    
    temp=0

print(num)

Submission status: Accepted

Solution code:
from functools import reduce

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

R = N
while True:
    if reduce(lambda x, y: x and y, [s not in D for s in list(str(R))]):
        break
    R += 1
print(R)

Submission status: Accepted

Solution code:
a,b=map(int,(input().split()))
c=set(input())
while sum(i in c for i in str(a))>0:
	a+=1
print(a)

Submission status: Accepted

Solution code:
from functools import reduce

def obsession(n, disliked):
    def nearest(digit):
        for i in range(digit, digit + 10):
            mod10 = i % 10
            if mod10 not in disliked:
                return (mod10, i != mod10)

    will_pay = list(map(int, str(n)))
    index = 0
    while index < len(will_pay):
        digit = will_pay[index]
        if digit in disliked:
            substitute, carry = nearest(digit)
            will_pay[index] = substitute

            # Propagate zeroes (or nearest) to the right
            i = index + 1
            substitute, _ = nearest(0)
            while i < len(will_pay):
                will_pay[i] = substitute
                i += 1

            # Propagate carry to the left
            i = index - 1
            while carry and i >= 0:
                substitute, carry = nearest(will_pay[i] + 1)
                will_pay[i] = substitute
                i -= 1
            if carry:
                will_pay.insert(0, nearest(1)[0])
                index += 1
        index += 1
    return reduce(lambda x, y: x * 10 + y, will_pay, 0)


if __name__ == '__main__':
    n, _ = map(int, input().split())
    disliked = set(map(int, input().split()))
    print(obsession(n, disliked))

Submission status: Accepted

Solution code:
import sys

debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False
if debug_mode:
    import os
    inf = open(os.path.basename(__file__).replace(".py", ".in"))

    def input():
        return inf.readline()
else:
    inf = sys.stdin

# ==============================================================

def main():
    n, k = [int(x) for x in input().strip().split()]
    d = [x for x in input().strip().split()]

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


main()

# ==============================================================

if debug_mode:
    inf.close()

Submission status: Accepted

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

def check(a):
  a=str(a)
  for i in range(len(a)):
    if int(a[i]) in A:
      return False
  return True

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=set(map(str,input().split()))
for i in range(n,10*n):
    a=list(str(i))
    a=set(a)
    if a&d==set():
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d=list(input().split())
ans=n
p=0
for i in range(10*n+1):
    s=str(ans)
    for j in range(len(str(s))):
        if s[j] in d:
            break
    else:
        break
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
AC
"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens = set(forbiddens)
    ans = N
    repeat = True
    
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
                
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens.sort()

    ans = N
    repeat = True
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
    return ans


def main(args):
    # N, K = 9999, 1
    # forbiddens = [9]
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
price, num = map(int,input().split())
dislike = list(input().split())
ans = price
p = 0
for i in range(10*price+1):
    s = str(ans)
    for j in range(len(str(s))):
        if s[j] in dislike:
            break
    else:
        break
    ans += 1
print(ans)

Submission status: Accepted

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

    while 1:
        f = 0
        hoge = str(n)
        for i in range(len(hoge)):
            for j in range(k):
                if(int(hoge[i]) == D[j]):
                    f = 1
                    break
                if f == 1:
                    break
            if f == 1:
                break
        if f == 0:
            print(n)
            break
        n += 1

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def c_IrohaObsession(N, K, D):
    d = [str(i) for i in D]
    i = N
    while True:
        for c in str(i):
            if c in d:
                break
        else:
            return i
        i += 1
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D))

Submission status: Accepted

Solution code:
(n, k), d = map(int, raw_input().split()), set(raw_input().split())
for _ in xrange(n, 100001):
    if not set(str(_)) & d:
        print _
        break

Submission status: Accepted

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

for i in range(N, 100000):
    a = list(str(i))
    a = set(a)
    if a & D == set():
        print(i)
        break

Submission status: Accepted

Solution code:
def solve(d,s):
    for i in range(len(d)):
        if d[i] in s:
            return 1
    return 0

N,K = map(int,input().split())
D = list(map(str,input().split()))
m = N
while  solve(D,str(m)):
    m += 1
print(m)

Submission status: Accepted

Solution code:
n=int(input().split()[0])
d=set(input())
while len(set(str(n))&d)>0:
    n+=1
print(n)

Submission status: Accepted

Solution code:
N,K=map(int,raw_input().split())
D=map(int,raw_input().split())
n=[0,1,2,3,4,5,6,7,8,9]

a=[]	#Allowed numbers
for i in n:
	if i not in D:
		a.append(i)


i=N
while True:
	for j in D:
		if str(i).find(str(j))!=-1:
			break
	else:
		print str(i)
		break
	i+=1

Submission status: Accepted

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

for i in range(N, 100001):
    set_n = set(list(str(i)))
    for s in set_n:
        if s in D:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
[n, k] = map(int, raw_input().split())
d = raw_input().split()
while True:
    ok = True
    for c in str(n):
        if c in d:
            ok = False
            break
    if ok:
        print n
        break
    n += 1

Submission status: Accepted

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


def valid(n):
    while n > 0:
        digit = n % 10
        if digit in d:
            return False
        n = int(n / 10)
    return True


for num in range(n, 10 * n):
    if valid(num):
        print(num)
        break

Submission status: Accepted

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

def digits(n):
  res = set()
  while n > 0:
    res = res.union(set([n%10]))
    n //= 10
  return res

for price in range(N, 10000000000000000):
  if digits(price).isdisjoint(D):
    print(price)
    break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""042-c"""

import sys


def solve(dislike_digits_table, first_like_digit, N):
    """Solve."""
    for i, _ in enumerate(N):
        c = N[i]
        while dislike_digits_table[int(c)]:
            if c == '9':
                if i == 0:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 '1' + '0' * len(N))
                else:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 str(int(N[0:i+1]) + 1)
                                    + '0' * len(N[i+1:]))
            else:
                c = chr(ord(c) + 1)
            N = N[0:i] + c + '0' * len(N[i+1:])

    return N


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                                in enumerate(dislike_digits_table)
                                if not v))

    print(solve(dislike_digits_table, first_like_digit, N))


if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
import math
a,b=(int(i) for i in input().split()) 
s=[int(i) for i in input().split()] 
n=[0,1,2,3,4,5,6,7,8,9]
n1 = [val for val in n if val not in s]
n1.sort()
keta=int(math.log10(a) + 1)
n_number=10-b
aa=str(a)
answer=[]
OKANE1=0
OKANE2=0
OKANE3=0
OKANE4=0
OKANE5=0

for i in range(n_number+1):
  for j in range(n_number+1):
    for k in range(n_number+1):
      for l in range(n_number+1):
        for m in range(n_number):
          if i!=0: 
            OKANE1=n1[i-1]
          if j!=0:          
            OKANE2=n1[j-1]
          if k!=0:           
            OKANE3=n1[k-1]
          if l!=0:           
            OKANE4=n1[l-1]
            
          OKANE5=n1[m]
          OKANE=10000*OKANE1+1000*OKANE2+100*OKANE3+10*OKANE4+OKANE5  
          if a<=OKANE:
            answer.append(OKANE)
print(min(answer))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().strip().split())
l = map(int, raw_input().strip().split())
ls = []
for x in l:
	ls.append(str(x))

def has_string(ns):
	r = True
	for x in ls:
		if x not in ns:
			pass
		else:
			r = False
	return r

while n < 100000:
	ns = str(n)
	if has_string(ns):
		print(ns)
		exit()
	else:
		n+=1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
  A.append(i)
for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)

for i in L:
  for j in L:
    for k in L:
      for l in L:
        for m in L:
          A.append(\
10000*i+1000*j+100*k+10*l+m)

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

Submission status: Accepted

Solution code:
from itertools import count


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

    for c in count(N):
        c = str(c)
        for d in D_list:
            if d in c:
                break
        else:
            print(c)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = N
while(1):
    j = True
    for d in D:
        if d in str(ans):
            j = False
            break
            
    if j == True:
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
nums = [int(x) for x in input().split()]
N,K = nums[0],nums[1]
D = set([int(x) for x in input().split()])

ans = N

def solve(M):
    M = [int(x) for x in str(M)]
    for m in M:
        if m in D: return False
    return True


while(1):
    if solve(ans):
        print(ans)
        break
    else:
        ans +=1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = list(map(str,input().split()))
ans = N
while sum([d in str(ans) for d in D]):
	ans+=1
print(ans)

Submission status: Accepted

Solution code:
a, _ = map(int, raw_input().split())
b = "".join(raw_input().split())
b = set(b)

for i in xrange(a, 99999999):
  if b.isdisjoint(str(i)):
    print i
    break

Submission status: Accepted

Solution code:
N,K = map(int, raw_input().split())
dislike = raw_input().split()
like = [str(n) for n in range(10) if str(n) not in dislike]

for n in range (N,100000):
  for d in str(n):
    if d in dislike: break
  else:
    print n
    break

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())
W = filter(lambda x: not x in D, range(10))
def dfs(x):
    if x >= N:
        return x
    return min([dfs(10*x + d) for d in W])
print min([dfs(i) for i in W if (i > 0)])

Submission status: Accepted

Solution code:
def isValid(n,l):
    s = str(n)
    for c in s:
        if c in l:
            return False
    return True

n,k = map(int, raw_input().split())
dls = raw_input().split()
for i in range(n,100000):
    if isValid(i,dls):
        print i
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,k = map(int,raw_input().split())
d = map(int,raw_input().split())
flg = 1
num = n-1
while(flg):
    num += 1
    strnum = str(num)
    check = [strnum.find(str(i))+1 for i in d]
    flg = sum(check)
print(num)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
D = list(map(int,input().split()))
for i in range(N*10):
    n = str(N + i)
    ok = True
    for j in D:
        if n.find(str(j)) != -1:
            ok = False
            break
    if ok:
        print(n)
        break

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, K = map(int, input().split())
    D = [str(i) for i in input().split()]
    ans = 0

    for m in range(N, 10**6):
        if canbuy(N, D, m):
            ans = m
            break

    print(m)

def canbuy(N, D, m):
    m = str(m)

    for d in D:
        if m.find(str(d)) != -1:
            return False

    return True


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools
a=set([0,1,2,3,4,5,6,7,8,9])
n,_=map(int,input().split())
b=map(int,input().split())
l=len(str(n))
c=set(b)^a
for i in range(l,l+2):
    for x in itertools.product(c,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=n:print(d);exit()

Submission status: Accepted

Solution code:

from itertools import product

N, K = [int(_) for _ in input().split()]
D = set([int(_) for _ in input().split()])
valid = list(set(range(10)) - D)

x = set()
for r in range(1,6):
    for p in product(valid, repeat=r):
        x.add(int(''.join([str(i) for i in p])))

for n in sorted(x):
    if n >= N:
        print(n)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dislikes = list(map(int, input().split()))
m = n
while True:
    m = list(str(m))
    l = []
    for p in m:
        if int(p) not in dislikes:
            l.append(p)
            continue
        else:
            m = int(''.join(m))+1
            break
    if len(l) >= len(str(n)):
        if int(''.join(l))>=n:
            break
print(''.join(m))

Submission status: Accepted

Solution code:
def run_code(N, K, ds):

    dislike_digits_set = set(i for i in ds)
    avail_digits = [i for i in range(10) if i not in dislike_digits_set]
    avail_min = avail_digits[0]

    def get_next_digit(d):
        last = 10
        for ad in (avail_digits + [last]):
            if ad >= d:
                if ad == last:
                    return (1, avail_min)
                else:
                    return (0, ad)

    def fill_last_kth_digits(n_digits, d, k):
        n = len(n_digits)
        for i in range(k):
            n_digits[n - i - 1] = d
        return n_digits

    def to_num(n_digits):
        num = 0
        n = len(n_digits)
        for i in range(n):
            num += n_digits[i] * 10**(n-i-1)
        return num

    def to_digits(num):
        return [int(i) for i in str(num)]

    def search_nearest_larger(num):
        n_digits = to_digits(num)
        n = len(n_digits)

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue
            if inc > 0:
                num += 10**(n-i)
                n_digits = fill_last_kth_digits(to_digits(num), avail_min, n-i)
                return search_nearest_larger(to_num(n_digits))
            else:
                n_digits[i] = d_out
                return to_num(fill_last_kth_digits(n_digits, avail_min, n-i-1))

        return to_num(n_digits)

    return search_nearest_larger(N)


N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
res = run_code(N, K, ds)
print(res)

Submission status: Accepted

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

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

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,k = LI()
    s = set(LS())
    for i in range(n,n*100):
        t = set(_ for _ in str(i))
        if not (t & s):
            return i

    return 0


print(main())

Submission status: Accepted

Solution code:
N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(N, 100000+1):
    if set(str(i)) & D == set():
        print i
        exit()

Submission status: Accepted

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

def check(num):
    for i in range(len(num)):
        for j in d:
            if int(num[i])==j:
                return False
    return True

while(not check(str(n))):
    n+=1
print(n)

Submission status: Accepted

Solution code:
# coding: utf-8;

def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        f = True
        for a in str(n):
            if int(a) not in usable_num:
                f = False
                break
        if f: break
        n += 1
    print(n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8;

def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        if len(set(map(int, str(n))) - set(usable_num)) == 0:
            break
        else:
            n += 1
    print(n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import combinations


def func(i, d, now, use, st):
    if i >= d:
        st.append(now)
        return

    for x in use:
        func(i + 1, d, now + str(x), use, st)


def solve():
    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)

    for i in range(len(str(n)), len(str(n)) + 2):
        st = []
        func(0, i, "", use, st)
        for x in sorted(st):
            if int(x) >= n:
                return x


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,raw_input().split())
d=set(map(int,raw_input().split()))
chk=set([str(i) for i in range(10) if i not in d])
while 1:
    tmp=set(str(n))
    if len(tmp&chk)==len(tmp):
        print n
        break
    n+=1