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

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

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

dec_num = [i for i in range(0, 10)]

able_use_num_lis = list(map(str, set(dec_num) - set(num_exclude)))

num_len = len(str(N))

output_list = []

def dfs(cur, num, able_use_num_lis):
    if num != '':
        if int(num) >= N:
            output_list.append(int(num))
    if len(str(N)) + 1 == cur:
        return
    
    for add_num in able_use_num_lis:
        ret = dfs(cur + 1, num + add_num, able_use_num_lis)
    return output_list

print(min(dfs(0, '', able_use_num_lis)))

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

while True:
  if len( set(str(N)).intersection(D)) == 0:
    print(N)
    exit()
  else:
    N += 1

Solution (Python):
import itertools
n, k = map(str, input().split())

ok = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
d = set(map(str, input().split()))
ok.difference_update(d)

ok_list = list(ok)
ok_list.sort()
ans = ""

if ok_list[-1] * len(n) < n:
  ans = ok_list[0] * (len(n) + 1) if ok_list[0] != "0" else ok_list[1] + "0" * len(n)
else:
  for nums in itertools.product(ok_list, repeat=len(n)):
    num = "".join(nums)
    if n <= num:
      ans = num
      break

print(ans)

Solution (Python):
N, K = map(int, input().split())
dislike = []
for i in range(0, 10):
	dislike.append(False)
D = list(map(int, input().split()))
for i in range(0, K):
	dislike[D[i]] = True
Y = N
while True:
	flag = True
	for i in range(0, len(str(Y))):
		if dislike[int(str(Y)[i])]:
			flag = False
			break
	if flag:
		print(Y)
		break
	Y += 1

Solution (Python):
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 I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LS()

  ans=1
  while True:
    if ans>=n:
      s=str(ans)

      f=True
      for x in s:
        if x in l:
          f=False
          break

      if f:
        return ans

    ans+=1

print(main())

Solution (Python):

n, m = [ int(v) for v in input().split() ]
num_list = [ v for v in input().split() ]
t = n
while True:
	if all([ ( v not in num_list ) for v in list(str(t))]):
		print(t)
		break
	t += 1

Solution (Python):

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

flag = True
while flag:
    check_result = False
    for i in d:
        if i in list(str(n)):
            check_result =True
            break
    if check_result:
        n+=1
    else:
        flag=False
print(n)

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

dislikes = set(input().split())

price = set(str(n))

while price & dislikes:
    n += 1
    price = set(str(n))

print(n)

Solution (Python):

n, k = map(int, input().split())
nglist = list(input().split())
while True:
    strn = str(n)
    flag = True
    for ng in nglist:
        if ng in strn:
            flag = False
            break
    if flag:
        break
    else:
        n += 1
print(n)

Solution (Python):
def main():
    n,k=map(int,input().split(' '))
    d = input().split(' ')
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break

if __name__=='__main__':
    main()

Solution (Python):
def equal(n, available):
  return n in available 

def less(n, available):
  return n < sorted(available, reverse=True)[0]

def greater(n, available):
  return n > sorted(available, reverse=True)[0]
  


def upper_next(n, available):  
  for v in sorted(available):
    if n < v:
      return v
  return 1/0

  
n_str, _ = [v for v in input().split()]
n_s = [0]
n_s.extend([int(n_str[i:i+1]) for i in range(len(n_str))])

d_s = [int(v) for v in input().split()]

available = set(list(range(10))) - set(d_s)



min_available = sorted(available)[0]
max_available = sorted(available, reverse=True)[0]

ans = [0]
ans.extend([min_available] * (len(n_s) - 1))

eq = True
for i in range(1, len(n_s)):
  
  if eq:
    if equal(n_s[i], available):
      ans[i] = n_s[i]
      continue
    else:
      eq = False
      
      if less(n_s[i], available):
        ans[i] = upper_next(n_s[i], available)
        
        break
      else:
        for j in range(i - 1, -1, -1):
          
          if ans[j] == max_available:
            ans[j] = min_available
          else:
            
            ans[j] = upper_next(ans[j], available)
            
            break
        break


begin = 0
if ans[0] == 0:
  begin = 1
ans_val = "".join(map(lambda x:str(x), ans[begin:]))

print(ans_val)

Solution (Python):
def main():
    n,k=map(int,input().split(' '))
    d = list(input().split(' '))
    for i in range(n,10*n+1):
        if not set(list(str(i)))&set(d):
            print(i)
            break


main()

Solution (Python):




Likes = set()


def check(n):
  global Likes
  while n > 0:
    if n%10 not in Likes:
      return False
    else:
      n //= 10
  return True    

def main():
  global Likes
  N,K = map(int, input().split())
  Dn = list(map(int, input().split()))
  Likes = set(range(10))-set(Dn)
  while True:
    if check(N):
      return N
    else:
      N += 1

if __name__ == "__main__":
  print(main())

Solution (Python):
N, K = map(int, input().split())
d = list(map(int, input().split()))

for i in range(N, 100000):
    flag = True
    tmp = i
    for j in reversed(range(len(str(i)))):
        if (tmp // (10 ** j)) in d:
            flag = False
            break
        else:
            tmp = tmp % (10 ** j)

    if flag:
        print(i)
        break

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



while True:
    a = str(n)
    flag = False
    for i in range(len(d)):
        if str(d[i]) in a:
            flag = True
            n+=1
            break
    if not flag:
        break

print(n)

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
b=True
while b:
  b1=False
  l1=list(str(n))
  for i in l1:
    if int(i) in l:
      b1=True
  if b1==False:
    b=False
    print(n)
    break
  else:
    n+=1

Solution (Python):
def dfs(i, s, l):
    if i == len(s):
        return ''
    for j in l:
        if j == int(s[i]):
            ans = dfs(i + 1, s, l)
            if ans is not None:
                ans += str(j)
                return ans
        elif j > int(s[i]):
            ans = str(l[0]) * (len(s) - i - 1) + str(j)
            return ans
    return None

n, k = map(int, input().split())
ns = str(n)
d = list(map(int, input().split()))
l = [i for i in range(10) if i not in d]
ans = dfs(0, ns, l)
if ans is None:
    if l[0] == 0:
        ans = str(l[1]) + str(l[0]) * len(ns)
    else:
        ans = str(l[0]) * (len(ns) + 1)
else:
    ans = ans[::-1]
print(ans)

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

ans = N
while True:
    tmp = ans
    finish = True
    while tmp > 0:
        if tmp % 10 in D:
            finish = False
            break
        tmp //= 10
    if finish:
        break
    ans += 1
print(ans)

Solution (Python):
ints = list(map(int, input().split()))
li = list(map(int, input().split()))

number = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
dislike = set(li)
like = number - dislike
for i in range(ints[0], 100000):
    flag = 0
    price = [int(j) for j in str(i)]
    length = len(price)
    for k in range(length):
        if price[k] in like:
            flag += 1
    if flag == length:
        break
print(i)

Solution (Python):
n,k = map(int, input().split())
d = set(input().split())
while True:
    s = set(list(str(n)))
    if all([i not in d for i in s]):
        print(n)
        break
    n += 1

Solution (Python):
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 I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  
  l=LI()

  a=0
  while True:
    a+=1
    if a>=n:
      f=True
      for x in list(str(a)):
        if int(x) in l:
          f=False
          break
      if f:
        return a

print(main())

Solution (Python):
nk = input().split()
d = input().split()


def hantei(int_siraverukazu):
    lst_siraverukazu = list(str(int_siraverukazu))
    onazi_t_tigau_f = []
    for i in range(int(nk[1])):
        for j in range(len(lst_siraverukazu)):
            if d[i] != lst_siraverukazu[j]:
                onazi_t_tigau_f.append(False)
            else:
                onazi_t_tigau_f.append(True)
    return onazi_t_tigau_f

serch_num  = int(nk[0])
kekka = hantei(serch_num)

while True:
    kekka = hantei(serch_num)
    if True in kekka:
        serch_num += 1
        continue
    if True not in kekka:
        result = serch_num
        break
print(result)

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


k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10




while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            
            break
    if flg == False:
        k = N
        k += 1
    else:
        break


print(N)

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

k = N
"""while k > 0:
    lst.append(k % 10)
    k //= 10



while 1:
    flg = True
    lst = []
    N = k
    while k > 0:
        lst.append(k % 10)
        k //= 10
    lst.reverse()
    
    for i in range(len(lst)):
        if lst[i] in D:
            flg = False
            break
    if flg == False:
        k = N
        k += 1
    else:
        break
print(N)

Solution (Python):

lst_1 = input().split()

N = lst_1[0]
K = int(lst_1[1])

lst_N = list(N)

lst_hate = input().split()

flg = True

while 1:

    for i in range(len(lst_N)):

        for j in range(len(lst_hate)):

            if lst_N[i] == lst_hate[j]:
                flg = False
                break

    if flg == True:
        break

    N = ''.join(lst_N)
    N = int(N)
    N += 1
    lst_N = list(str(N))

    flg = True

N = ''.join(lst_N)
print(N)

Solution (Python):
N, K = map(int, input().split())
d = set(input().split())
for v in range(N, 10 * N):
    if not set(str(v)) & d:
        print(v)
        break

Solution (Python):
from itertools import product
N,K = list(map(int,input().split(" ")))
Ds =  list(map(int,input().split(" ")))
nums = [0,1,2,3,4,5,6,7,8,9]
nums = list(set(nums) - set(Ds))

cand = []
for j in range(1,6):
    for i in product(nums, repeat=j):
        i = list(map(str,i))
        temp = "".join(list(i))
        temp = int(temp)
        cand.append(temp)
cand.sort()

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

Solution (Python):
a,b = map(int,input().split())
c=list(map(int,input().split()))
for i in range(a,99999):
    j = list(str(i))
    n=0
    for k in j:
        for d in c:
            if int(k)==d:
                n+=1
    if n==0:
        print(i)
        break

Solution (Python):
n,k = map(int,input().split())
d = list(input().split(' '))
def check(num):
    globals()
    s = str(n)
    for i in d:
        if i in s:
            return True
    return False
while(check(n)):
    n+=1
print(n)

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
D = [x for x in range(0,10) if x not in D]
n = len(str(N))
K = 10 - K

def bi(x):
    o = [0]*n
    c = 0
    while x > 0:
        o[c] = x % K
        x //= K
        c += 1
    return o

m = int(str(min(filter(lambda x:x,D)))+str(min(D))*n)

for i in range(K**n):
    o = bi(i)
    j = int(''.join([str(D[x]) for x in o]))
    if N <= j:
        m = min(m,j)

print(m)

Solution (Python):
N, K = map(int,input().split())
D = list(input().split())
while 1:
        price = str(N)
        flag = True
        for p in price:
                for d in D:
                        if p == d:
                                flag = False
        if flag == True:
                break
        N += 1
print(N)

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

while True:
    ok = True
    for c in str(n):
        if int(c) in ds:
            ok = False
            break

    if ok:
        print(n)
        break
    else:
        n += 1

Solution (Python):
n,k=map(int,input().split())
d=input().split()
stopcode=False
while stopcode==False:
  for i in range(len(str(n))):
    if str(n)[i] in d:
      n+=1
      break
    elif i+1==len(str(n)):
      stopcode=True
      break
print(n)

Solution (Python):
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=n
def judge(m,li):
    ml=list(str(m))
    for i in ml:
        if int(i) in li:
            return True
    return False
while judge(ans,l):
    ans+=1
print(ans)

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

while D & set(str(N)):
    N += 1
print(N)

Solution (Python):
n = int(input().split()[0])
a = set(input())

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

print(n)

Solution (Python):
n, k = map(int, input().split())
d = list(map(str, input().split()))
while True:
    strn = str(n)
    for i in range(len(strn)):
        if strn[i] in d:
            n += 1
            break
        if i == len(strn)-1:
            print(n)
            exit()

Solution (Python):
N,K = map(int,input().split())
*D, = map(int,input().split())
for i in range(N,100000):
    for n in str(i):
        if int(n) in D:
            break
    else:
        break
print(i)

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

Solution (Python):


import math

n,k=map(int,input().split(" "))

klist=input().split(" ")
def hantei(n,kl):
    if len(str(n))==4:
        while math.floor(n/1000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    if len(str(n))==5:
        while math.floor(n/10000)==kl or \
        math.floor(n/1000)-10*math.floor(n/10000)==kl or \
        math.floor(n/100)-10*math.floor(n/1000)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or\
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==3:
        while math.floor(n/100)==kl or \
        math.floor(n/10)-10*math.floor(n/100)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==2:
        while math.floor(n/10)==kl or \
        n-10*math.floor(n/10)==kl:
            n=n+1
    elif len(str(n))==1:
        while n==kl:
            n=n+1
    return int(n)
n2=n
for kl in klist:
    kl=int(kl)
    n=hantei(n,kl)
while n!=n2:
    n2=n
    for kl in klist:
        kl=int(kl)
        n=hantei(n,kl)
print(n)

Solution (Python):
n, k = [int(n) for n in input().split()]
d = [n for n in input().split()]
 
while(1):
 
    for l in list(str(n)):
        if l in d:
            break
    else:
        print(n)
        break
 
    n += 1

Solution (Python):
n,k=map(int,input().split())
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
    
for x in range(n,10*n):
    flg=True
    for d in str(x):
        if d not in s:
            flg=False
    if flg:
        print(x)
        break

Solution (Python):

ans=10**6
n,k=map(int,input().split())
p=[int(i) for i in input().split()]
s=[]
for i in range(10):
    if i not in p:
        s.append(str(i))
        
for a in s+['0']:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    x=map(int,[a+b+c+d+e,b+c+d+e,c+d+e,d+e,e])
                    for i in x:
                        if i>=n:
                            ans=min(i,ans)
print(ans)

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

while(1):

    for l in list(str(n)):
        if l in d:
            break
    else:
        print(n)
        break

    n += 1

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

for i in range(N, N * 10 + 1):
    check = True
    for n in str(i):
        if int(n) in D:
            check = False
    if check:
        print(i)
        exit()

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

N_list = list(str(N))
flag = True
cnt = 0

while True:
    N_list = list(str(N+cnt))
    if flag:
        for j, n in enumerate(N_list):
            if int(n) in D:
                cnt += 1
                break
            elif j==len(N_list)-1:
                flag = False
    else:
        break
print(N+cnt)

Solution (Python):
import itertools
n,k = map(int,input().split())
a = list(map(str,input().split()))
d = [str(i) for i in range(10)]

for c in a:
    d.remove(c)

res = -1
for l in itertools.product(d,repeat=len(str(n))):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
if res != -1:
    print(res)
    exit(0)
for l in itertools.product(d,repeat=len(str(n))+1):
    x = int(''.join(l))
    if x>=n and (res==-1 or x<res):
        res = x
print(res)

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

while D & set(str(N)):
    N += 1

print(N)

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

for i in range(N, 10 * N + 1):
    for s in str(i):
        if int(s) in D:
            break
    else:
        print(i)
        quit()

Solution (Python):

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

def check(n, d):
    n = str(n)
    for nstr in n:
        if nstr in d:
            return False
    return True
while True:
    if check(N, D):
        print(N)
        break
    else:
        N += 1

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

n=N
while True:
    queue=0
    nstr=str(n)
    for i in nstr:
        if i in D:
            queue=1
    if queue==0:
        print(n)
        break
    n+=1

Solution (Python):
def get_greater_equals(number, target, exclude_digits):
    if number >= target:
        return number
    results = []
    for i in range(10):
        if not i in exclude_digits:
            if i == 0 and number == 0:
                continue
            results.append(
                get_greater_equals(number * 10 + i, target, exclude_digits))
    return min(results)


def main():
    n, k = [int(x) for x in input().rstrip().split(" ")]
    exclude_digits = [int(x) for x in input().rstrip().split(" ")]

    result = get_greater_equals(0, n, exclude_digits)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
 
white_num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N, K = map(int, input().split())
black_num_list = list(map(int, input().split()))
 
white_num_list = list(set(white_num_list).difference(set(black_num_list)))
num_combination = list(itertools.product(white_num_list, repeat = len(str(N))))
 
num_list = []
for num in num_combination:
    if num[0] == 0:
        continue
    num_list.append(int(''.join(map(str, num))))
    
num_list = sorted(num_list)
 
def price(N, num_list, white_num_list):
    for num in num_list:
        if num >= N:
            return num
    
    placeholder = str(min(white_num_list)) * (len(str(N)) + 1)
    if placeholder[0] == '0':
        white_num_list.remove(0)
        placeholder = str(min(white_num_list)) + placeholder[1:]
    return int(placeholder)
      
print(price(N, num_list, white_num_list))

Solution (Python):
N, K = map(int, input().split())
D = list(input().split())
while not all([n not in D for n in str(N)]):
    N += 1
print(N)

Solution (Python):
N, K = map(int, input().split())
D = set(map(str, input().split()))
i = N
while(1):
    if len(D & set(list(str(i)))) == 0:
        print(i)        
        break
    i += 1

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

flag = False
for a in range(N, 10*N):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

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

flag = False
for a in range(N, 10*N+1):
	ans = list(str(a))
	for b in range(len(ans)):
		if ans[b] in D:
			break
		if b == len(ans) - 1 and ans[b] not in D:
			print(a)
			flag = True
	if flag:
		break

Solution (Python):
n, k = map(int, input().split())
d = [str(i) for i in input().split()]
for i in range(n, 10*n+1):
    if len(set(list(str(i))) & set(d)) == 0:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split(' '))
d_list = input().split(' ')
for h in range(10):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                for l in range(10):
                    number = h * 10000 + i * 1000 + j * 100 + k * 10 + l
                    result = set(list(str(number)))
                    if set(d_list) & result != set():
                        continue
                    if number >= N:
                        print(number)
                        break
                else:
                    continue
                break
            else:
                continue
            break
        else:
            continue
        break
    else:
        continue
    break

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

for i in range(N, 10*N+1):
    sn = str(i)
    flg = True
    for c in sn:
        if c in D:
            flg = False
            break
    if flg:
        print(i)
        break

Solution (Python):
N,K = map(int,input().split())
D = set(map(str,input().split()))
def check(n,d):
    n = str(n)
    for nstr in n:
        if nstr in d:
            return False
    return True
while True:
    if check(N,D):
        print(N)
        break
    else:
        N = N+1

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

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

Solution (Python):
N,K=map(int,input().split())
D={int(i) for i in input().split()}

C = {0,1,2,3,4,5,6,7,8,9} - D
A=[]
for i in range(9*N+1):
    if (N+i)%10 in C:
        if ((N+i)%100)//10 in C:
            if ((N+i)%1000)//100 in C:
                if ((N+i)%10000)//1000 in C:
                    if (N+i)//10000 in C:
                        A.append(N+i)
                    elif (N+i)//10000==0:
                        A.append(N+i)
                elif (N+i)//1000==0:
                    A.append(N+i)
            elif (N+i)//100==0:
                A.append(N+i)
        elif (N+i)//10==0:
            A.append(N+i)



print(min(A))

Solution (Python):
import sys
N, K = map(int, input().split())


d = list(map(int, input().split()))
d_set = set(d)

num_set = set([1,2,3,4,5,6,7,8,9,0])
enable = num_set - d_set




def dfs(s):
  
  global ans
  
  if s != "":
    if int(s) >= N:
      
      ans.append(int(s))
      return

  for num in enable:
    if len(s) == 0 and num == 0:
      continue
    else:
      (dfs(s+str(num)))
    
  return

ans = []
dfs("")

print(min(ans))

Solution (Python):
def main():
	N, K = map(int, input().split())
	D = list(map(int, input().split()))
	rec = 0
	rec2 = 1
	for d in D:
		if rec != d:
			break
		rec += 1
	for d in D:
		if rec2 != d:
			break
		rec2 += 1

	strN = str(N)
	carry = False
	ans = ""
	for i in range(len(strN)-1, -1, -1):
		cur = int(strN[i])
		chanegd = False
		if carry:
			cur += 1
			carry = False
			chanegd = True
			if cur == 10:
				carry = True
		while cur in D:
			cur += 1
			chanegd = True
			if cur == 10:
				cur = 0
				carry = True
		if carry:
			ans = str(rec)*(len(strN)-i)
		else:
			if chanegd:
				ans = str(rec)*(len(strN)-i-1)
			ans = str(cur)+ans
	if carry:
		ans = str(rec)*(len(strN))
		if rec == 0:
			ans = str(rec2) + ans
		else:
			ans = str(rec) + ans

	print(ans)


if __name__ == '__main__':
	main()

Solution (Python):
N, K = map(int, input().split())
s = list(map(int, input().split()))

x = N
while set(list(str(x))) & set(list(str(s))):
    x += 1
    continue
else:
    print(x)

Solution (Python):
def task_c():
    """
    https://atcoder.jp/contests/abc042/tasks/abc042_c
    """
    n, k = map(int, input().split())
    dd = input().split()

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

    
task_c()

Solution (Python):


n, k = map(int, input().split())
nums = input().split()

pay = n
disLike = True

while disLike:
    disLike = False
    for j in range(len(str(pay))):
        if str(pay)[j] in nums:
            disLike = True
            pay += 1

print(pay)

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

import sys

for i in range (N, 10**5+1):
    if len(set(list(str(i))) & set(D)) == 0:
        print(i)
        sys.exit()

Solution (Python):
n,k = map(int,input().split())
ng = set(input().split())
while len(set(str(n))&ng):
    n+=1
print(n)

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

for i in range(N, 100000):
    j = str(i)
    more = False
    for k in D:
        if j.count(k) > 0:
            more = True
            break
    if not more:
        ans = i
        break

print(ans)

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

for i in range(N, 100000):
    j = str(i)
    more = False
    for k in D:
        if j.count(k) > 0:
            more = True
            break
    if not more:
        ans = i
        break

print(ans)

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

for i in range(N, 100000):
    j = str(i)
    more = False
    for k in D:
        if j.count(k) > 0:
            more = True
            break
    if not more:
        ans = i
        break

print(ans)

Solution (Python):
N, K = map(int, input().split())
l = input().split()

result = N - 1


def hasNum(result, l):
    for num in l:
        if num in str(result):
            return False

    return True


while True:
    result = result + 1

    if hasNum(result, l):
        print(result)
        break

Solution (Python):
N,_ = map(int,input().split())
lists=list(map(str,input().split()))

for i in range(N,100000):
    flg=True
    for j in str(i):
        if j in lists: 
            flg = False
            break
    if flg:
        print(i)
        break

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

num = N
while True:
    tmp = str(num)
    if all(i not in D for i in tmp):
        break
    num += 1

print(num)

Solution (Python):

def read_input():
    n, k = map(int, input().split())
    dlist = list(map(int, input().split()))

    return n, k, dlist


def check_inclusion(dislike, target):
    return any(d in target for d in dislike)


def submit():
    n, k, dlist = read_input()

    target = n
    checkee = [int(digit) for digit in str(target)]

    while check_inclusion(dlist, checkee):
        target += 1
        checkee = [int(digit) for digit in str(target)]

    print(target)

if __name__ == '__main__':
    submit()

Solution (Python):
n,k = map(int,input().split())
ok = set(input().split())
while len(set(str(n))&ok):
    n+=1
print(n)

Solution (Python):
N, _ = map(int, input().strip().split())
D = input().strip().split()
for ans in range(N, 100000):
    if len(set(str(ans)) & set(D)) == 0:
        print(ans)
        break

Solution (Python):
n,k=map(int,input().split())
m=list(map(int,input().split()))
for i in range(n,100000):
  k=1
  for a in str(i):
    if int(a) in m:
      k=0
  if k:
    print(i)
    break

Solution (Python):
N,K = map(int,input().split())
D = input().split()
for i in range(N, 10*N+1):
  for j in str(i):
    if j in D:
      break
  else:
    print(i)
    exit()

Solution (Python):
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N, K = map(str, input().split())
    D = list(map(str, input().split()))

    nums = set([str(i) for i in range(10)])
    safe = sorted(list(nums - set(D)))
    min_safe = safe[0]
    if min_safe == '0':
        min_safe = safe[1]

    digit = len(str(N))
    safe_num = list(product(safe, repeat=digit))
    ans = 10**5
    for n in safe_num:
        m = int(''.join(n))
        l = int(min_safe + ''.join(n))
        if m >= int(N):
            ans = min(ans, m)

        if l >= int(N):
            ans = min(ans, l)


    return ans


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

Solution (Python):
n,k = map(int,input().split())
d = input().split()
while len(set(str(n)) & set(d)) !=0:
    n +=1
print(n)

Solution (Python):
n,k = map(int,input().split())
d = list(map(str,input().split()))
for i in range(n,10*n):
    ans = 0
    for j in str(i):
        if not j in d:
             ans += 1
    if ans==len(str(i)):
        print(i)
        exit()

Solution (Python):
def check(x,sample):
    x=str(x)
    for i in x:
        if i in sample:
            return False
    return True

def main():
    n,k=map(int,input().split())
    sample=input().split()
    while 1:
        if check(n,sample):
            print(n)
            return;
        n+=1
main()

Solution (Python):

 
def solve(N, K, D):
    i = 0
    while(True):
        test = N + i
        test_str = str(test)
        
        for j in range(K):
            index = -1
            index = test_str.find(D[j])
            if(index>=0):
                break
        if(index == -1):
            break
        i += 1
    print(test)
    
if __name__ == '__main__':
    N, K = map(int, input().split())
    D = [str(d) for d in input().split()]
    
    solve(N, K, D)

Solution (Python):
import itertools
n,k=map(int,input().split())
D=list(map(int,input().split()))
N=set(i for i in range(10))
C=list(N-set(D))
ans=float("inf")
for a in list(itertools.product(C,repeat=len(str(n)))):
  m=int("".join(map(str,a)))
  if m>=n:
    ans=min(ans,m)
if ans==float("inf"):
  for a in list(itertools.product(C,repeat=len(str(n))+1)):
    m=int("".join(map(str,a)))
    if m>=n:
      ans=min(ans,m)
print(ans)

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