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())
dislike = [str(i) for i in input().split()]
strn = str(n)

while(1):
  flag = 1
  for i in range(len(strn)):
    if strn[i] in dislike:
      flag = 0
  if flag == 1:
    print(n)
    break
  else:
    n += 1
    strn = str(n)

Solution (Python):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]


def dfs(n):
    if n != '':
        if n[0] == '0':
            return 10 ** 7
        elif int(n) >= N:
            return int(n)
    output = 10 ** 7
    for l in L:
        output = min(output, dfs(n + str(l)))
    return output


print(dfs(''))

Solution (Python):
N,K=map(int,input().split())
D=set(input().split())
while 1:
    l=str(N)
    for i in range(len(l)):
        if l[i] in D:
            break
    else:
        print(N)
        break
    N+=1

Solution (Python):
n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
    s=str(n)
    s=list(s)
    check=0
    for i in s:
        if i in d:
            break
        check+=1
        if check==len(s):
            print(''.join(s))
            exit()
    n+=1

Solution (Python):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

N, K = [int(x) for x in stdin.readline().rstrip().split()]
D = [int(x) for x in stdin.readline().rstrip().split()]

L = [x for x in range(10) if x not in D]
ans = 10 ** 7


def dfs(n):
    global ans
    if n != '' and n[0] == '0':
        return
    if n != '' and int(n) >= ans:
        return
    if len(n) >= len(str(N)):
        if int(n) >= N:
            ans = int(n)
    for l in L:
        dfs(n + str(l))


dfs('')
print(ans)

Solution (Python):
a, n = map(int, input().split())
b = list(map(str, input().split()))
c = str(a)
while True:
    check = True
    for i in range(len(c)):
        if c[i] in b:
            c = str(int(c) + 1)
            check = False
            break
    if check:
        print(c)
        break

Solution (Python):
def main():
    n,k=map(int,input().split())
    a=input()
    for i in range(n,100000):
        bl = 1
        for j in str(i):
            if j in a:
                bl=0
                continue
        if bl:
            return i
print(main())

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

Solution (Python):
n, k = input().split()
d = set(input().split())
while not set(n).isdisjoint(d):
    n = str(int(n) + 1)
else:
    print(n)

Solution (Python):
n, k = input().split()
d = set(input().split())
while True:
    if set(n).isdisjoint(d):
        print(n)
        break
    else:
        n = str(int(n) + 1)

Solution (Python):
def main():
    n, k = (int(i) for i in input().split())
    d = {i for i in input().split()}
    while set(str(n)) & d:
        n += 1
    print(n)
if __name__ == '__main__':
    main()

Solution (Python):
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, k = na()
ddd = input().split()
for i in range(n, 100000):
    flag = True
    for c in str(i):
        if c in ddd:
            flag = False
            break
    if flag:
        ans = i
        break
print(ans)

Solution (Python):
import itertools

N, K = map(int,input().split())
D = list(map(int,input().split()))
N = str(N)
d = []
d_min = 10
for i in range(10):
    if i in D:
        continue
    else:
        if i != 0:
            d_min = min(d_min, i)
        d.append(str(i))
if '0' in d:
    ans = str(d_min) + '0' * len(N)
else:
    ans = str(d_min) * (len(N) + 1)
ans = int(ans)
for s in itertools.product(d, repeat=len(N)):
    s = ''.join(s)
    s = int(s)
    if s >= int(N):
        ans = min(ans, s)
print(ans)

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

for i in range(n,10**6):
  flag = 0 
  for j in str(i):
    if int(j) in List: 
      flag = 1
      break
      
  if flag == 0:
    print(i)
    exit()

Solution (Python):
N, K = map(int, input().split())
Dlist = list(map(int, input().split()))
    
alist = list(set([0,1,2,3,4,5,6,7,8,9]) - set(Dlist))
if sum(x==0 for x in alist) == 0:
    b = min(alist)
else:
    b = min(list(set(alist)-set([0])))
strN = str(N)
c = ""
ans = ""
flag = True
for i in range(len(strN)):
    iN = int(strN[i])
    if sum(x>=iN for x in alist) == 0:
        ans = str(b) + str(min(alist))*len(strN)
        flag = False
        break
    elif sum(x==iN for x in alist) == 0:
        ans = c + str(min([a for a in alist if a>iN])) + str(min(alist))*(len(strN)-1-i)
        flag = False
        break
    else:
        c = c + str(iN)

if flag:
    print(N)
else:
    print(int(ans))

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

while True:
  ns = str(n)
  exists_dislike_number = False
  for ds in d:
    if ns.count(str(ds)) > 0:
      exists_dislike_number = True
  
  if exists_dislike_number:
    n += 1
  else:
    break

print(n)

Solution (Python):
N,K = map(int,input().split())
D = list(map(str,input().split()))
while(1):
    a = str(N)
    if not any(i in a for i in D):
        break
    N+=1
print(N)

Solution (Python):
def is_correct(disabled, val):
  for c in str(val):
    if c in disabled:
      return False
  return True

def main():
  n, k = [int(x) for x in raw_input().split(' ')]
  disabled = [x for x in raw_input().split(' ')]
  while not is_correct(disabled, n):
    n += 1
  print(n)

main()

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
while 1<2:
  nn=list(map(int,list(str(n))))
  if len(set(nn+d))<len(set(nn))+len(set(d)):
    n+=1
  else:
    print(n)
    break

Solution (Python):
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
while True:
    flag=0
    for money_element in list(str(money)):
        if money_element in no_list:
            flag=1
            money+=1
            break
    if flag==0:
        print(money)
        break

Solution (Python):
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
for i in range(money,100000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Solution (Python):
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
for i in range(money,100000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break

Solution (Python):
n,k=map(int,input().split())
d=[int(i) for i in input().split()]
d=set(d)
i=0
while True:
    s=str(n)
    c=0
    for i in s:
        if int(i) in d:
            break
        else:
            c+=1
    if c==len(s):
        print(n)
        exit()
    n+=1

Solution (Python):
import itertools

N,K= map(int,input().split())
D = set(input().split())
while len(set(str(N))&D) != 0:
    N = N + 1
print(N)

Solution (Python):
n,k = map(int,input().split())
d = list(map(int,input().split()))
a = n
f = False
while f == False:
    li = []
    for i in str(a):
        li.append(int(i))
    if set(li) & set(d) == set():
        print(a)
        f = True
    else:
        a += 1

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

M = N
while True:
  N_ = 0
  for i,n in enumerate(N):
    if n in D:
      N_ += (int(n) + 1) * 10 ** (len(N) - 1 - i)
      break
    else:
      N_ += int(n) * 10 ** (len(N) - 1 - i)
  else:
    break
  N = str(N_)
          
print(N)

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

Solution (Python):
n, k = (int(x) for x in input().split())
dislike_numbers = input().split()

for i in range(n, 99999):
    if all(dn not in str(i) for dn in dislike_numbers):
        print(i)
        break

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    D = inputList()
    
    base = list(range(10))
    for vol in D:
        base.remove(vol)
        
    ans = ""
    NN = str(N)
    flg = False
    for i,val in enumerate(NN):
        isInp = False
        for j,vol in enumerate(base):
            if flg == True:
                ans += str(vol)
                isInp = True
                break
            tmp = int(val)
            if tmp == vol:
                ans += val
                isInp = True
                break
            elif tmp < vol:
                flg = True
                ans += str(vol)
                isInp = True
                break
            else:
                continue
        
        if isInp == False:
            ans += "*"
    
    if "*" not in ans:
        print(ans)
        sys.exit()
    
    ans = list(ans)
    ans_T = ""
    if ans[0] == "*" or 1 == 1:
        if base[0] != 0:
            ans_T += str(base[0])
        else:
            ans_T += str(base[1])
        for i in range(len(str(N))):
            ans_T += str(base[0])
        print(ans_T)
        sys.exit()
    
if __name__ == "__main__":
	main()

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    D = inputList()
    
    base = list(range(10))
    for vol in D:
        base.remove(vol)
        
    ans = ""
    NN = str(N)
    flg = False
    for i,val in enumerate(NN):
        isInp = False
        for j,vol in enumerate(base):
            if flg == True:
                ans += str(vol)
                isInp = True
                break
            tmp = int(val)
            if tmp == vol:
                ans += val
                isInp = True
                break
            elif tmp < vol:
                flg = True
                ans += str(vol)
                isInp = True
                break
            else:
                continue
        
        if isInp == False:
            ans += "*"
    
    if "*" not in ans:
        print(ans)
        sys.exit()
    
    ans = list(ans)
    ans_T = ""
    if ans[0] == "*" or 1 == 1:
        if base[0] != 0:
            ans_T += str(base[0])
        else:
            ans_T += str(base[1])
        for i in range(len(str(N))):
            ans_T += str(base[0])
        print(ans_T)
        sys.exit()
        
    '''
    mem = []
    for i in ans:
        if i == str(base[-1]):
            mem.append(1)
        elif i == "*":
            mem.append(2)
        else:
            mem.append(0)
    
    ttt = ""
    tmp = ""
    flg = False
    for i, val in enumerate(ans):
        if mem[i] == 2:
            ttt += str(base[0])
            flg = True
        else:
            ttt += "-"
        if flg == False:
            tmp = val
            
    print("".join(ans))
    '''
    
if __name__ == "__main__":
	main()

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

Ds = set(input().split())

n = N

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

print(n)

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

nums = []
for x in range(10):
    if x in ds:
        nums.append(1)
    else:
        nums.append(0)

res = 0
for x in range(n, n*10):
    ys = list(map(int,list(str(x))))
    flag = False
    for y in ys:
        if nums[y]:
            flag = True
            break
    if flag:
        continue
    else:
        res = x
        break
print(res)

Solution (Python):
n, k = map(int, input().split())
d = list(map(str, input().split()))
num = [0 for _ in range(10)]

for v in d:
    num[int(v)] = 1

for j in range(10 * n):
    v = n + j
    v_l = list(str(v))
    flag = True
    for i in v_l:
        if num[int(i)] == 1:
            flag = False
            break
    if flag:
        print(v)
        exit()

Solution (Python):


import copy

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


use_list = list(set(range(10)) - set(d_list))
n_list = [int(x) for x in list(str(N))]


keta_list = [x in use_list for x in n_list]

def can_update(old_n):
    kouho_n_list = [x for x in use_list if x > old_n]
    if kouho_n_list:
        return True
    else:
        return False


k_index = keta_list.index(False) if False in keta_list else -1

if k_index != -1:
    is_ok = False

    for index in range(k_index, -1, -1):
        
        old_n = n_list[index]
        
        if can_update(old_n):
            
            kouho_n_list = [x for x in use_list if x > old_n]
            new_n = min(kouho_n_list)
            new_n_list = n_list[:index] + [new_n]
            
            if index < len(keta_list):
                new_n_list += [min(use_list)] * (len(keta_list) - (index+1))
            ans = int(''.join([str(x) for x in new_n_list]))
            is_ok = True
            break

        if not is_ok:
            
            new_n = sorted(use_list)[1] if min(use_list) == 0 else min(use_list)
            
            new_n = str(new_n) + str(min(use_list)) * len(keta_list)
            ans = int(new_n)

else:
    
    ans = N

print(ans)

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

    F = []
    for i in range(10):
        if i not in D: F.append(i)

    l = len(str(N))
    cand = [""]
    for _ in range(l):
        temp = []
        for s in cand:
            for f in F:
                temp.append(s+str(f))
        cand = temp

    lv = [int(s) for s in cand]
    for s in sorted(lv):
        if int(s) >= N: return int(s)

    minf = 9
    for f in F:
        if f > 0: minf = min(minf, f)

    cand = sorted(cand)
    return int(str(minf) + cand[0])

if __name__ == '__main__':

    print(main())

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

flag=False
while True:
  yen=str(n)
  for i in range(len(yen)):
    if int(yen[i]) in d:
      n+=1
      flag=True
      break
  if flag:
    flag = False
    continue
  break
print(n)

Solution (Python):
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



def main():
    n, k = LI()
    n_list = LI()
    i = n
    while True:
        flag = 0
        for j in n_list:
            if str(j) in str(i):
                flag = 1
        if flag == 0:
            break
        i += 1
    return i





print(main())

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

dislike_number = set(map(int, input().split()))
num = set([i for i in range(10)])
ok_num = list(num - dislike_number)
ok_num = sorted(ok_num)



max_len = len(str(N))
widths=[str(max(ok_num))]*(max_len+1)
min_value=10**(max_len+1)

for i in range(0,max_len+1):
    if i==0:
        temp=int("".join(widths[1:]))
        if N <= temp < min_value:
            min_value=temp
            widths[0]="0"
            continue
    for num in ok_num:
        widths[i]=str(num)
        temp=int("".join(widths))
        if N <= temp < min_value:
            min_value=temp
            break
print(min_value)

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

while(True):
    n = str(N)
    flag = True
    for i in range(len(n)):
        if(int(n[i]) in d):
            flag = False
            break
    if(flag):
        break
    else:
        N += 1
print(N)

Solution (Python):
n, k = list(map(int, input().split()))
set_d = set(map(int, input().split()))
g = n
while(True):
    set_g = set(str(g))
    set_g = [int(i) for i in set_g]
    for i in set_g:
        if i in set_d:
            g += 1
            break
    else:
        break
print(g)

Solution (Python):
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, k = map(int, input().split())
    dl = set(map(int, input().split()))

    for i in range(n, 100000):
        if i < n:
            continue
        candi = list(map(int, list(str(i))))
        available = True
        for c in candi:
            if c in dl:
                available = False
                break
        if available:
            print(i)
            return


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

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


nums = []
for c in list('0123456789'):
    if c in D:
        pass
    else:
        nums.append(c)



ret = []
def dfs(next_value, nums, ans):
    ans += next_value

    if int(ans) >= N:
        ret.append(ans)
        return

    for c in nums:
        
        if ans == '0' and c == '0':
            pass
        else:
            dfs(c, nums, ans)

    return ans

dfs('0', nums, '')

A = list(map(int, ret))
print(min(A))

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

for i in range(n,100000):
    ans=list(str(i))
    flag=0
    for x in ans:
        if x  in d:
            flag=1
    if flag==0:
        print(''.join(ans))
        sys.exit()

Solution (Python):
def main():
    n, k = map(int, input().split())
    d = list(input().split())
    i = n
    while True:
        stri = list(str(i))
        flg = True
        for j in d:
            if j in stri:
                flg = False
        if flg:
            print(i)
            return
        i += 1


if __name__ == '__main__':
    main()

Solution (Python):
n, _ = [int(x) for x in input().split()]
dn = set(input().split())

i = n
answer = n
while len(set(str(n)) & dn) > 0:
    n += 1
print(n)

Solution (Python):
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
 

while True:    
    N_str = str(N)
    frag = 0
    for i in range(len(N_str)):
        if int(N_str[i]) in l:
            
            frag = 1
            break
    if frag == 0:
        break
    else:
        N += 1
print(N)

Solution (Python):

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

Solution (Python):
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]


while True:    
    N_str = str(N)
    frag = 0
    for i in range(len(N_str)):
        if int(N_str[i]) in l:
            
            frag = 1
            break
    if frag == 0:
        break
    else:
        N += 1
print(N)

Solution (Python):
n,k=map(int,input().split())
d=set(map(str,input().split()))
i=n
a=[]
for j in range(len(str(n))):
	a.append(str(n)[j])
a=set(a)
while i<10**5+1:
	if len(a&d)==0:
		print(i)
		exit()
	else:
		i+=1
		a=[]
		for j in range(len(str(i))):
			a.append(str(i)[j])
		a=set(a)

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

while True:
  s=str(n)
  if not any(tmp in s for tmp in str(d)):
    break
  n+=1
print(n)

Solution (Python):
inputted = input().split(" ")
N=int(inputted[0])
K=int(inputted[1])
s = [i for i in input() if i != ' ']

num=0
while True:
  num+=1
  match=[i for i in str(num) if i in s]
  if num>=N and len(match)==0:
    print(num)
    break

Solution (Python):
[N,K] = list(map(int, input().split()))
D = [x for x in input().split()]
while True:
  S = str(N)
  if not any(d in S for d in D):
    break
  N += 1
print(N)

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

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

Solution (Python):
n,k=map(int,input().split())
d=list(map(str,input().split()))
def judge(x,y):
  X=str(x)
  ret=1
  for i in X:
    if(i in y):
      ret=0
      break
  return ret
while(True):
  if(judge(n,d)==1):
    break
  else:
    n += 1
print(n)

Solution (Python):


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

for i in range(n,10*n):
    if any([j in d for j in list(str(i))]):
        continue
    print(i)
    break

Solution (Python):
N, K = map(int, input().split())
Ds = set(input().split())
for i in range(N, 100000):
  s = str(i)
  ng = any(map(lambda c: c in Ds, s))
  if not(ng):
    r = i
    break
print(r)

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

while True:
    S = str(N)
    if not any(d in S for d in D):
        break
    N += 1
print(N)

Solution (Python):
n, k = map(int, input().split())
dlist = input().split()
flg = True
while flg:
    s = str(n)
    for t in s:
        if t in dlist:
            n += 1
            break
    else:
        flg = False
print(n)

Solution (Python):
N,n=map(int,input().split())
dislike=input().split()
count=0
while(1):
  flag=1
  for i in range(n):
    if dislike[i] in str(N+count):
      flag=0
      break
  if flag:
    print(N+count)
    break
  count+=1

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

for i in range(n, 100000):
    flag = True
    price = str(i)
    for d in d_array:
        str_d = str(d)
        if str_d in price:
            flag = False
    else:
        if flag:
            print(i)
            exit()

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

ans = N
flg = True
while flg:
    s = str(ans)
    for c in s:
        if c in D:
            ans += 1
            break
    else:
        flg = False
print(ans)

Solution (Python):
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 10000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    if N > ans:
        for x in range(1,10):
            if x not in D:
                ans = x * 10000
                if 0 in D:
                    ans += x * 1000 + x * 100 + x * 10 + x
                break
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Solution (Python):
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 100000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

Solution (Python):
N_str, K=input().split()
K=10-int(K)
N_digit=list(map(int,list(N_str)))
D=sorted(list(map(int,input().split())))
D=[d for d in range(10) if d not in D]

l_digit=[n>D[-1] for n in N_digit]

if any(l_digit):
  N_n=l_digit.index(True)
  if not any([n is not D[-1] for n in N_digit[0:N_n]]):
    out=list(str(D[1] if D[0]==0 else D[0]))
    out+=[str(D[0]) for i in range(len(N_digit))]
  else:
    flag=False
    out=[]
    for i in range(N_n):
      if not flag:
      	for j in range(K):
          if D[j]>=N_digit[i]:
            out.append(str(D[j]))
            if D[j]!=N_digit[i]:
              flag=True
              break
      else:
        out.append(str(D[0]))
    for i in range(N_n,len(N_digit)):
      out.append(str(D[0]))
else:
  out=[]
  flag=False
  for n in N_digit:
    if not flag:
      for j in range(K):
        if D[j]>=n:
          out.append(str(D[j]))
          if D[j]>n:
            flag=True
          break
    else:
      out.append(str(D[0]))
      
print(int("".join(out)))

Solution (Python):
n,K = map(int,input().split())
use = [0,1,2,3,4,5,6,7,8,9]
useless = list(map(int,input().split()))
for i in range(K):
  use.remove(useless[i])
k = 10 - K
time = [0]
def suc(time):
  now = 0
  while True:
    if now >= len(time):
      time.append(0)
      break
    elif time[now] != k-1:
      time[now] += 1
      break
    else:
      time[now] = 0
      now += 1
  return time



while True:
  pay = 0
  for j in range(len(time)):
    pay += use[time[j]] * 10 ** j
  if pay >= n:
    print(pay)
    break
  time = suc(time)

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

ans = 0
for i in range(n,100000):
    s = str(i)
    pay = True
    for j in range(len(s)):
        if s[j] in d:
            pay = False
            break
    if pay:
        ans = i
        break
print(ans)

Solution (Python):
import itertools
n, k = map(int, input().split())
d = list(map(int, input().split()))
ls = []
for i in range(10):
    if i not in d:
        ls.append(i)
mp = 10 ** 9
for j in range(len(str(n)), 7):
    for i in itertools.product(ls, repeat=j):
        m = int("".join(map(str, i)))
        if m >= n:
            mp = min(mp, m)
print(mp)

Solution (Python):
n,k = map(int,input().split())
d = list(map(str,input().split()))
a = 0 
for i in range(n,100000):
    for j in d:
        if j in str(i): 
            a = 1 
            break
        elif j == d[-1]: a=0 
    if a==0:  
        print(i)
        break

Solution (Python):
n,k = map(int,input().split())
l = set(input().split())
ans = n
flag = True
while len(set(str(ans))&l) > 0:
  ans += 1
print(ans)

Solution (Python):


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

k = input()
s = [int(j) for j in k.split(" ")]
valIn = 0

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

def irohacheck(n):
	global valIn
	valIn = 0
	
	num = digit(n)
	
	for i in range(len(num)):
		if s.count(num[i])>0:
			valIn+=1

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

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

Solution (Python):
n,k = map(int,input().split())
alllst = ['0','1','2','3','4','5','6','7','8','9']
dislike = [str(i) for i in input().split()]

lst = set(alllst) - set(dislike)

while True:
    st = set(str(n))
    if st.issubset(lst):
        print(n)
        break
    else:
        n += 1

Solution (Python):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict






INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)









N, K = [int(x) for x in input().split()]
D = [x for x in input().split()]

while True:
    isOK = True
    for n in list(str(N)):
        if n in D:
            isOK = False
            break
    if isOK:
        print(N)
        sys.exit()
    N += 1

Solution (Python):
N, K = map(int, input().split())
nums = list(input().split())
for i in range(N, 100000):
  checked = True
  for char in str(i):
    if char in nums:
      checked = False
      break
  if checked:
    print(i)
    break

Solution (Python):
n, l = map(int, input().split())
s = input().split()
 
def is_hate(nums, price):
  for n in nums:
    if str(n) in str(price):
      return True
  else:
    return False
 
while(is_hate(s, n)):
  n += 1
print(n)

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

def is_hate(nums, price):
  for n in nums:
    if str(n) in str(price):
      return True
  else:
    return False

while(is_hate(s, n)):
  n += 1
print(n)

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

for i in range(10*n - n):
    c = str(n+i)
    
    for j in a:
        if j in c:
            break
    
    else:
        ans = c
        break
        
print(ans)

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

for i in range(10*n - n):
    c = str(n+i)
    
    for j in a:
        if j in c:
            break
    
    else:
        ans = c
        break
        
print(ans)

Solution (Python):

tmp = raw_input("").split(' ')
n = int(tmp[0])
k = int(tmp[1])
tmp = raw_input("")
exclude_set = map(int, tmp.split(' '))

def binarySearch(arr, target):
  l = 0
  r  = len(arr) - 1
  while l <= r:
    m = (l + r)//2
    if arr[m] == target:
      return True
    elif arr[m] > target:
      r = m - 1
    elif arr[m] < target:
      l = m + 1
  return False

def check(n_digits, exclude_set):
  for i in range(0, len(n_digits)):
    if binarySearch(exclude_set, n_digits[i]) == True:
      return False
  return True
for i in range(n, 10**5):
  tmp = i
  n_digits = []
  while tmp > 0:
    n_digits.append(tmp%10)
    tmp = int(tmp/10)
  
  if check(n_digits, exclude_set) == True:
    print i
    break

Solution (Python):
cost, hate = map(int, input().split())
hate_num = list(map(int, input().split()))

hate_str = list(str(hate_num))
pay = cost
flag = True
while flag:
    pay_str = list(str(pay))
    for i in range(len(pay_str)):
        if set([pay_str[i]]) - set(hate_str) != set([pay_str[i]]):
            pay += 1
            flag = True
            break
        else:
            flag = False
print(pay)

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
number_set = {0,1,2,3,4,5,6,7,8,9}
for i in D:
    number_set.remove(i)    

while True:
    N_str = str(N)
    list_N = list(N_str)
    list_N = [int(n) for n in list_N]
    N_set = set(list_N)

    if N_set <= number_set:
        print(N)
        break
    else:
        N+=1