Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

 1 ≦ N < 10000

 1 ≦ K < 10

 0 ≦ D_1 < D_2 < … < D_K≦9

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

Input

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

N K
D_1 D_2 … D_K

Output

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

Sample Input 1

1000 8
1 3 4 5 6 7 8 9

Sample Output 1

2000

She dislikes all digits except 0 and 2.

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

Sample Input 2

9999 1
0

Sample Output 2

9999



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


Sample output:
2000

Submission status: Accepted

Solution code:
n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n)
for i,d in enumerate(n):
 if d in u:continue
 n[i:]=[next(e for e in u if e>d)]+[z]*(len(n)-i-1)
 for j in range(i-1,-1,-1):
  if n[j+1]<':':break
  n[j:j+2]=[next(e for e in u if e>n[j]),z]
 else:
  if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n)
print"".join(n)

Submission status: Accepted

Solution code:
n, k = map(int,raw_input().split())
s = set(raw_input().split())
for i in range(n,100000):
	if len(s - set(list(str(i)))) == k:
		print i
		break

Submission status: Accepted

Solution code:
n, _ = map(int, raw_input().split())
d = set(map(int, raw_input().split()))
while len(set(map(int, str(n))) & d) > 0:
    n += 1
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+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())
arr=list(map(int,input().split()))
x=1
while x!=0:
	x=0
	n+=1
	for i in range(k):
		if str(n-1).find(str(arr[i]))!=-1:
			x+=1
print(n-1)

Submission status: Accepted

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

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

ans = N
while True:
    ans = str(ans)
    for num in D:
        if ans.find((str(num))) != -1:
            break
    else:
        break
    ans = int(ans) + 1

print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
for i in range(N, 10**9):
    if not set(str(i)) & D:
        print(i)
        break

Submission status: Accepted

Solution code:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))

def main():
    n,k = readLine_int_list()
    d = readLine_int_list()
    i = [i for i in range(10) if not i in d]
    for ii in range(n, 10**9):
        l = [int(x) for x in list(str(ii))]
        ll =[q for q in l if q in d]
        if len(ll) == 0:
            print(ii)
            break
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def valid(num,l):
    while(num>0):
        if (num%10) in l:
            return 0
        num = num//10
    return 1

n,k=map(int,input().split(' '))
l = [int(x) for x in input().split(' ')]
for i in range(100000):
    if valid(n+i,l) == 1:
        print(n+i)
        break

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N, K = map(int, input().split())
D = list(map(int, input().split()))
for tmp in range(N, 10*N+1):
    flag = True
    factor = list(map(int, str(tmp)))
    for num in D:
        if num in factor:
            flag = False
            break
    if flag:
        print(tmp)
        break

Submission status: Accepted

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

def main():
    N, K = input().split()
    l = list(set(list('0123456789')) - set(input().split()))
    t = int(N)
    m = 100000
    for i in itertools.product(l, repeat=len(N)):
        if int(''.join(i)) >= t:
            m = min(m, int(''.join(i)))
    for i in itertools.product(l, repeat=len(N)+1):
        if int(''.join(i)) >= t:
            m = min(m, int(''.join(i)))
    print(m)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))


N, K = rli()
D = set(map(int, input().split()))
All = {1,2,3,4,5,6,7,8,9,0}
All.difference_update(D)

ans = N
for i in range(N*10):
    ls = set(map(int, str(ans)))
    ls.difference_update(All)
    if(ls == set()):
        print(ans)
        break
    ans += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(100000):
    for x in str(N):
        if x in D:
            break
    else:
        print N
        break
    N += 1

Submission status: Accepted

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


def main(n, D):
    D = set(D)
    while set(str(n)) & D:
        n += 1
    return n


if __name__ == '__main__':
    n, _ = [int(e) for e in input().split()]
    D = [e for e in input().split()]
    print(main(n, D))

Submission status: Accepted

Solution code:
import itertools
n,_=map(int,input().split())
b=map(int,input().split())
l=len(str(n))
c=set(b)^set([0,1,2,3,4,5,6,7,8,9])
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:
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:


inpt = input().split(" ")

maxNum = inpt[0]

dislike = input().split(" ")
dislike = [int(a) for a in dislike]

likeArray = []

for i in range(0,10):
    if not i in dislike:
        likeArray.append(i)

ans = ""
flag = False
for c in maxNum:
    if flag :
        ans += str(min(likeArray))
    else:
        if int(c) in likeArray:
            ans += c
        elif len([a for a in likeArray if a > int(c)])>0:
            ans += str(min([a for a in likeArray if a > int(c)]))
            flag = True
        else:
            ans = str(min([a for a in likeArray if a > 0]))
            for i in range(0, len(maxNum)):
                ans += str(min(likeArray))
            break    
print(ans)

Submission status: Accepted

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

f=1
a=n
while f==1:    
    for i in range(k):
        if str(d[i]) in list(str(a)):
            f=1
            a+=1
            break
    else:
        f=0
print a

Submission status: Accepted

Solution code:
mark=[0 for i in range(10)]
n,k=map(int,raw_input().split())
l=map(int,raw_input().split())


def check(num):
	temp=num

	while(temp>0):
		d=temp%10
		if d in l:
			return 0
		temp=temp//10
	return 1




while True:

	if check(n)==1:
		print n
		break
	n+=1

Submission status: Accepted

Solution code:

N,K=map(int,raw_input().split( ))
numlist=map(int,raw_input().split( ))
def checknum(num):
    t = num
    while(t):
        check=t%10
        k=0
        while(k<K):
            if check == numlist[k]:
                return 0
            k+=1
        t=t/10
    return 1


while(1):
    if(checknum(N)):
        print N
        break
    N+=1

Submission status: Accepted

Solution code:
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ipair():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def spair():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
#

def join(s):
    return ''.join(s)

#iterate macro
def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)

#modulo macro
def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    else:
        return -1

###########


n,k = ipair()
d = map(int,raw_input().split(" "))

while 1:
    flag = 1
    for a in list(str(n)):
        if index(d,int(a))!=-1:
            flag = 0
    if flag:
        print n
        break
    n += 1

Submission status: Accepted

Solution code:
#coding: utf-8

inputs = map(int, raw_input().split())
n = inputs[0]
k = inputs[1]
d = map(int, raw_input().split())
p = []

p.append(n//10000)
p.append(n//1000 - p[0]*10)
p.append(n//100 - p[0]*100 - p[1]*10)
p.append(n//10 - p[0]*1000 - p[1]*100 - p[2]*10)
p.append(n%10)

topindex = 0

for i in range(5):
    if p[i] != 0:
        topindex = i
        break

    
while True:
    dex = 0
    for i in range(topindex,5):
        if p[i] in d:
            dex = 1
    if dex == 1:
        n += 1
        p = []
        p.append(n//10000)
        p.append(n//1000 - p[0]*10)
        p.append(n//100 - p[0]*100 - p[1]*10)
        p.append(n//10 - p[0]*1000 - p[1]*100 - p[2]*10)
        p.append(n%10)

        topindex = 0

        for i in range(5):
            if p[i] != 0:
                topindex = i
                break
    else:
        break

print(n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(input().split())
while any(s in D for s in str(N)):
    N += 1
print(N)

Submission status: Accepted

Solution code:
from functools import reduce
import operator as op

def mapAccumL(f, acc, xs):
    ys = []
    for x in xs:
        (acc, y) = f(acc, x)
        ys.append(y)
    return (acc, ys)

def unfoldl(f, init, finish):
    acc = init
    while not finish(acc):
        acc, y = f(acc)
        yield y

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = set(map(int, ds_str))

for m in range(n, 100000):
    mlist = list(unfoldl(lambda acc: (acc//10, acc%10), m, lambda acc: acc == 0))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Submission status: Accepted

Solution code:
from functools import reduce
import operator as op

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = set(map(int, ds_str))

for m in range(n, 100000):
    mlist = map(int, list(str(m)))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Submission status: Accepted

Solution code:
from functools import reduce
import operator as op

n = int(input().split(' ')[0])
ds_str = input().split(' ')
ds = list(map(int, ds_str))

for m in range(n, 100000):
    mlist = map(int, list(str(m)))
    if reduce(op.or_, map(lambda x:x in ds, mlist)):
        continue
    else:
        print(m)
        break

Submission status: Accepted

Solution code:
N, K = raw_input().split()
D = set(map(int,raw_input().split()))
L = sorted(set(range(10))-D)

pay=[]
for ind, d in enumerate(N):
    if ind == 0:
        w = len(N)
        ma, mi = max(L), min(L)
        tmp = ''.join([str(ma)]*w)
        tmp = int(tmp)
        if tmp < int(N):
            if L[0]==0:
                pay = [str(L[1])]+['0']*w
            else:
                pay = [str(L[0])] * (w+1)
            break

    if int(d) in D:
        for l in sorted(L):
            if l > int(d):
                pay+= [str(l)]+[str(L[0])]*(w-len(pay)-1)
                break
        else:
            for l in sorted(L):
                if l > int(N[ind - 1]):
                    pay = pay[:-1] + [str(l)] * (w - len(pay) + 1)
                    break
        break
    else:
        pay.append(d)

print ''.join(pay)

Submission status: Accepted

Solution code:
from collections import deque
n = map(int, raw_input().split())
n = n[0]

d = map(int, raw_input().split())
e = range(0,10)
for dd in d:
    e.remove(dd)

sn = str(n)
indexes = deque()
bg = False
for cn in sn:
    dn = int(cn)
    i = 0
    if bg:
        indexes.append(0)
        continue
    while i < len(e) and dn > e[i]:
        i+=1
    if i != len(e):
        indexes.append(i)
        if dn < e[i]:
            bg = True

    else: # carry up
        j = -1
        while -j < len(indexes):
            if indexes[j] + 1 < len(e): # able to up
                indexes[j] += 1
                break
            else:
                indexes[j] = 0
            j -= 1
        # print j,indexes
        if -j >= len(indexes) : # one more digit
            indexes.clear()
            if e[0] != 0:
                indexes.append(0)
            else:
                indexes.append(1)
            for l in xrange(len(sn)):
                indexes.append(0)
            break

        indexes.append(0)
ans = ""
while len(indexes) != 0:
    i = indexes.popleft()
    ans += str(e[i])
    # print ans
print ans

Submission status: Accepted

Solution code:
def check(n):
    return all(not int(i) in D for i in str(n))

N, K = map(int, raw_input().split())
D = map(int, raw_input().split())

while True:
    if check(N):
        print N
        break
    N += 1

Submission status: Accepted

Solution code:
import math

amount, avoid_num = tuple([ int(x) for x in raw_input().split() ])
avoids = tuple([ int(x) for x in raw_input().split() ])
non_avoids = tuple([ x for x in range(10) if x not in avoids ])
# print amount
# print avoid_num
# print avoids
# print non_avoids

result = amount
result_str = list(str(result))
length = len(result_str)
for index in range(1, length+1):
    num = int(result_str[-index])
    # print index, num
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            # print new_num
            result = int(result + (new_num - num) * math.pow(10, index-1))
            result_str = list(str(result))
        else:
            # print 'kuriage'
            result = int(result + (10 - num) * math.pow(10, index-1))
            result_str = list(str(result))
result = int(result)
while True:
    result_str = list(str(result))
    num = int(result_str[0])
    if num in avoids:
        new_num = None
        for x in non_avoids:
            if x > num:
                new_num = x
                break
        if new_num:
            result = int(result + (new_num - num) * math.pow(10, len(result_str)-1))
        else:
            result = int(result + (10 - num) * math.pow(10, len(result_str)-1))
    else:
        break

result_str = list(str(result))
base_str = list(str(amount))
for index in range(2, len(result_str)+1):
    num = int(result_str[-index])
    base_num = int(base_str[-index]) if index <= len(base_str) else None
    # print num, base_num
    if base_num is None or num > base_num:
        result_str[-index+1:len(result_str)] = [str(non_avoids[0])] * (index - 1)
# print int(result)
print ''.join(result_str)

Submission status: Accepted

Solution code:
N,K = map(int,raw_input().split())
D = raw_input().split()
cant = set(D)
for n in xrange(N,100000):
	u = set(list(str(n)))
	if len(cant - u) == K:
		print n
		break

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
c = n
while True:
    if not any(str(x) in str(c) for x in d):
        break
    c += 1
print(c)

Submission status: Accepted

Solution code:
import numpy as np

ret = []
use = []

def func(k, n):
    if k == 0:
        if n >= N:
            print(n)
            exit()
        return

    for i in use:
        func(k-1, n*10 + i)

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

num = np.array([i for i in range(10)])
f = np.array([True for i in range(10)])

D = list(map(int, input().split()))
for i in D:
    f[i] = False

use = num[f]

func(1, 0)
func(2, 0)
func(3, 0)
func(4, 0)
func(5, 0)

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools
n, k = map(int, raw_input().split())
ls = map(int, raw_input().split())
kls = []
for i in range(10):
    if i not in ls:
        kls.append(i)
#print ls,kls
ans_list = []
repeat_len = len(str(n))
while not ans_list:
    for element in itertools.product(kls, repeat=repeat_len):
        a = int("".join(map(str,element)))
        if a >= n:
            ans_list.append(a)
    repeat_len += 1
print ans_list[0]

Submission status: Accepted

Solution code:
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N, K = map(int, input().split(" "))
ds = list(map(int, input().split(" ")))
cs = []
for i in range(10):
    if i not in ds: cs.append(i)

ns = str(N)


def solve(N, digit):
    if digit == -1:
        return N
    n = int((N // (10**digit)) % 10)
    if n not in ds:
        return solve(N, digit - 1)
    else:
        new_N = N // (10**(digit + 1))
        new_N = new_N * (10**(digit + 1))
        for i in range(n + 1, 10):
            if i not in ds:
                new_N = new_N + (10**digit) * i
                return solve(new_N, digit-1)
        else:
            new_N = new_N + 10**(digit + 1)
            return solve(new_N, len(str(new_N))-1)

print(solve(N, len(str(N))-1))

Submission status: Accepted

Solution code:
import re
 
class IO_for_Contest(object):
    @staticmethod
    def my_input():
        #return raw_input()
        return input()
 
    @staticmethod
    def read_from_input():
        n, k = IO_for_Contest.read_n_int(2)
        d = IO_for_Contest.read_n_int(k)
        return n, d
 
    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()
 
    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())
 
    @staticmethod
    def read_n_int(n):
        return list(map( \
                int, \
                re.split('\s+', IO_for_Contest.my_input().strip())))[ : n]
 
def solve():
    n, d = IO_for_Contest.read_from_input()
    print(inner_solve(n, d))

def inner_solve(n, d):
    while True:
        s_n = str(n)
        success = False
        for i in range(len(s_n)):
            if int(s_n[i]) in d:
                break
        else:
            success = True
        if success:
            return n
        n += 1

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for x in xrange(n, 10**6):
    for c in str(x):
        if c in D:
            break
    else:
        print x
        break

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
vs = set(map(int, raw_input().split()))

while True:
    ok = True
    for c in str(n):
        if int(c) in vs:
            ok = False
            break
    if ok:
        break
    n += 1
print n

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
is_bad = [ False for d in range(10) ]
for d in map(int, raw_input().split()):
  is_bad[d] = True

def good(x):
  while x != 0:
    d = x % 10
    if is_bad[d]:
      return False
    x //= 10
  return True

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

Submission status: Accepted

Solution code:
from itertools import product
N, K = list(map(int, input().split()))
D = set(range(10)) - set(list(map(int, input().split())))
ans = float("inf")
for i in range(2):
    for s in product(D, repeat=len(str(N))+i):
        n = int("".join(map(str, s)))
        if n >= N and ans - N > n - N:
            ans = n
print(ans)

Submission status: Accepted

Solution code:
if __file__.startswith('/tmp/'):
	import sys; sys.stdin = open('input.txt')

n, k = map(int, raw_input().split())
d = ''.join(raw_input().split())

l = len(str(n)) + 1

m = n
while True:
	s = str(m)
	ok = True
	for c in s:
		if c in d:
			ok = False
			break
	if ok:
		print s
		break
	m += 1

Submission status: Accepted

Solution code:
[N,K]=[int(x) for x in raw_input().split()]
Dlist=raw_input().split()

ans=0
while(1):
    ans+=1
    if ans>=N:
        anstr=str(ans)
        Din=0
        for D in Dlist:
            if D in anstr:
                Din=1
        if not Din:
            print ans
            break

Submission status: Accepted

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

import itertools


def solve(money, dislike_numbers):
    for dm in itertools.count():
        pay = money + dm
        if set(map(int, str(pay))).isdisjoint(dislike_numbers):
            return pay


def main():
    money, _ = map(int, input().split())
    dislike_numbers = set(map(int, input().split()))
    print(solve(money, dislike_numbers))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while True:
    ok = True
    for d in D:
        if str(N).find(d) >= 0:
            ok = False
            break
    if ok:
        print(N)
        break
    N += 1

Submission status: Accepted

Solution code:
n,k=map(int,raw_input().split())
D=map(int,raw_input().split())
while 1:
    cnt=0
    for i in str(n):
        if int(i) in D:break
        else:
            cnt+=1
    if cnt==len(str(n)):
        print(n)
        quit()
    n+=1

Submission status: Accepted

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

s = N
n = int(N)
while 1:
    if all(c not in D for c in s):
        print(n)
        break
    else:
        n += 1
        s = str(n)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
D = set(map(int, input().split()))
i = N
while True:
    j = i
    flag = True
    while j > 0:
        r = j % 10
        if r in D:
            flag = False
            break
        j //= 10
    if flag:
        print(i)
        break
    i += 1

Submission status: Accepted

Solution code:
from sys import exit
from itertools import count

def read():
  return [int(x) for x in input().split()]

(N, K) = read()
D = input().split()

for i in count(N):
  if all(not d in str(i) for d in D):
    print(i); break

Submission status: Accepted

Solution code:
n, k = [int(x) for x in raw_input().split(' ')]
d = [int(x) for x in raw_input().split(' ')]
def check(n, d):
    for v in d:
        if str(v) in str(n):
            return False
    return True
while True:
    if check(n, d):
        print n
        break
    n += 1

Submission status: Accepted

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

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

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

Submission status: Runtime Error

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

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

minNum = min([digit for digit in range(0, 10) if digit not in ds])
maxNum = max([digit for digit in range(0, 10) if digit not in ds])

digits = [int(digit) for digit in N]

result = N
for index in range(0, len(digits)):
  digit = digits[index]
  if digit in ds:
    i = index
    if digit > maxNum:
      i = index - 1
      while i >= 0 and digits[i] == maxNum:
        i -= 1
    
    if i < 0:
      result = str(minNum) * (len(N) + 1)
    else:
      biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]])
      digits[i] = biggerDigit
      for j in range(i+1, len(digits)):
        digits[j] = minNum
      result = "".join([str(digit) for digit in digits])

print(result)

Submission status: Runtime Error

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

s = input()
s = s.split(" ")
ds = [int(digit) for digit in s]

minNum = min([digit for digit in range(0, 10) if digit not in ds])
maxNum = max([digit for digit in range(0, 10) if digit not in ds])

digits = [int(digit) for digit in N]

result = N
for index in range(0, len(digits)):
  digit = digits[index]
  if digit in ds:
    i = index
    if digit > maxNum:
      i = index - 1
      while i >= 0 and digits[i] == maxNum:
        i -= 1
    
    if i < 0:
      result = str(minNum) * (len(N) + 1)
    else:
      biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]])
      result = N[:i] + str(biggerDigit) + (str(minNum) * (len(N) - i - 1))

print(result)

Submission status: Runtime Error

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

def is_ok(num):
  s = str(num)
  for ng in d:
    if ng in s: return False
  
  return True

while True:
  if is_ok(n):
    print(n)
    exit()
  
  n += 1

Submission status: Runtime Error

Solution code:
# ARC058A

import itertools

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

# n, k = map(int, '1110 8'.split())
# d = set('1 3 4 5 6 7 8 9'.split())

valid = {'0', '1', '2', '3', '4', '5', '7', '6', '7', '8', '9'}
d2 = list(valid - d)
n2 = list(str(n))
pos = []
for i, c in enumerate(n2):
    if c not in d2:
        pos.append(i)
combinations = list(itertools.product(d2, repeat=len(pos)))

ans = []
for combination in combinations:
    for i in pos:
        n2[i] = combination[i]
    num = int(''.join(n2))
    ans.append(num)

for i in sorted(ans):
    if i >= n:
        print(i)
        break

Submission status: Runtime Error

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
FirstBigList = []
newMoney = list(oldMoney)
def FindFirstBig(okLines,m,FirstBig):
    for i in okLines:
        if i > m:
            FirstBig.append(i)
    return FirstBig

for i in range(10):
    if str(i) not in hateLines:
        okLines.append(str(i))

FirstFlag = -1
ProblemFlag = -1
for index, m in enumerate(oldMoney):
    if FirstFlag == -1:
        if m in hateLines:
            FirstBigList = FindFirstBig(okLines,m,FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[index] = FirstBigList[0]
                FirstFlag = index
            ProblemFlag = index
    elif FirstFlag != -1:
        newMoney[index] = okLines[0]

if oldMoney == newMoney:
    if ProblemFlag is not 0:
        FirstBigList.clear()
        while ProblemFlag:
            FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList)
            if len(FirstBigList) > 0:
                newMoney[ProblemFlag - 1] = FirstBigList[0]
                for i in range(ProblemFlag,len(newMoney),1):
                    newMoney[i] = okLines[0]
            if oldMoney == newMoney:
                ProblemFlag -= 1
    if ProblemFlag is 0:
        newMoney.insert(0,okLines[0])
        for i in range(ProblemFlag, len(newMoney), 1):
            newMoney[i] = okLines[0]
resultnew = "".join(newMoney)
print(resultnew)

Submission status: Runtime Error

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
#newMoney = 0
for i in range(10):
    if str(i) not in hateLines and str(i) > oldMoney[0]:
        okLines.append(i)
for index,m in enumerate(oldMoney):
    if m in hateLines and okLines is not None:
        oldMoney[index] = str(okLines[0])
result = "".join(oldMoney)
print(result)

Submission status: Runtime Error

Solution code:
oldMoney, hateNumberLength = map(list, input().split())
hateLines = list(str(input()).rsplit(" "))
okLines = []
newMoney = 0
for i in range(10):
    if str(i) not in hateLines and str(i) > oldMoney[0]:
        okLines.append(i)
for index,m in enumerate(oldMoney):
    if m in hateLines and okLines is not None:
        oldMoney[index] = okLines[0]
print("".join(oldMoney))

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
num=[]
sub=[]
ans=""

for i in [0,1,2,3,4,5,6,7,8,9]:
  if i not in d:
    num.append(i)

n=str(n)
for i in range(int(len(n))):
  if len(ans)>0:
    if int(ans[0])>=int(n[i-1]):
      subans=ans
      for w in range(int(len(n))-i):
        ans+="0"
    if ans>=n:
      print(ans)
      sys.exit()
    else:
      ans=subans
    
  for j in num:
    if j>=int(n[i]):
      sub.append(j)
  ans+=str(min(sub))
      
print(ans)

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
num=[]
ans=""
sub=[]

for i in [0,1,2,3,4,5,6,7,8,9]:
  if i not in d:
    num.append(i)

n=str(n)
for i in range(len(n)):
  if len(ans)>0:
    if str(ans[0])>=n[i-1] and min(num)>=int(n[i]):
      for w in range(int(len(n))-i):
        ans+=str(min(num))
      print(ans)
      sys.exit()
    
  for j in num:
    if j>=int(n[i]):
      sub.append(j)
      break
  ans+=str(min(sub))
  
print(ans)

Submission status: Runtime Error

Solution code:
import sys

n,k=map(int,input().split())
d=list(map(int,input().split()))
num=[]
ans=""
sub=[]

for i in [0,1,2,3,4,5,6,7,8,9]:
  if i not in d:
    num.append(i)

n=str(n)
for i in range(len(n)):
  if len(ans)>0:
    if str(ans[0])>=n[i-1] and min(num)>=int(n[i]):
      for w in range(int(len(n))-i):
        ans+=str(min(num))
      print(ans)
      sys.exit()
    
  for j in num:
    if j>=int(n[i]):
      sub.append(j)
      break
  ans+=str(min(sub))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = list(input().split())
for i in reversed(range(n, 10001)):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        ans = i
print(ans)

Submission status: Runtime Error

Solution code:

n,m = input().split()
k = int(n)
l = list(input().split())

for i in range(k,100000):
    for x in l:
        for x str(i):
            break
    else:
        print(i)
        break

Submission status: Runtime Error

Solution code:

n,m = input().split()
k = int(n)
l = list(input().split())

for i in range(k,100000):
    for x in l:
        for y str(i):
            break
    else:
        print(i)
        break

Submission status: Runtime Error

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

e = [0,1,2,3,4,5,6,7,8,9]
d = e - d

for i in d:
   for j in d:
      if int(ij) >= n:
        print(ij)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = map(str, input().split())
digits = set(d)
num = {str(i) for i in range(0,10)}
left = num - digits
for i in range(N, 100000):
    Num = set(str(i))
    if Num <= left:
        print(i)
        break