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())
D=list(map(int, input().split()))
use=[]
for i in range(10):
    if i not in D:
        use.append(i)
ans = ''

for n in list(map(int, list(str(N)))):
    if n > use[-1]:
        ans+=str(use[0])
    else:
        for i in use:
            if i >= n:
                ans+=str(i)
                break

if str(N)[0] < ans[0]:
    ans = ans[0]+str(use[0])*(len(ans)-1)

if N-int(ans) > 0:
    ans = str(use[0]) + str(use[0])*len(str(N)) if use[0]!=0 else str(use[1])+str(use[0])*len(str(N))



print(ans)

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

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

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

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

Solution (Python):
N, K = map(int, input().split())  
D = map(int, input().split())  
D_str = list(map(str, D))
m = N
 
while True:
    for n in str(m):
        if n in D_str:
            break
    else: 
        print(m)
        break
    m += 1

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
d = nl()
for i in range(n, 100001):
    lis = list(str(i))
    f = 0
    for j in lis:
        if int(j) in d:
            f = 1
    if f == 0:
        print(i)
        exit()

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

while True:
    for i in str(ans):
        if i in d:
            break
    else:
        print(ans)
        exit()
    ans += 1

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

while True:
    for n in str(m):
        if n in D_str:
            break
    else: 
        print(m)
        break
    m += 1

Solution (Python):
n,k=map(int,input().split())
D=input()
D_str=str(D)
i=0
string=D_str.split()
while True:
    judge=0
    fee=n+i
    fee_str=str(fee)
    for j in range(k):
        index=fee_str.find(string[j])
        judge = judge + index
    if judge == -k :
        break
    i=i+1
print(fee)

Solution (Python):
n,k=map(int,input().split())
d=[int(i) for i in input().split()]
t=n
while 1:
    x=t
    while 1:
        if x%10 in d:
            break
        else:
            x//=10
        if x==0:
            print(t)
            exit()
    t+=1

Solution (Python):
N, K = map(int, input().split())
dislike = list(map(int, input().split()))
 
for i in range(N, 10*N+1):
    num = list(map(int,str(i)))
    match = list(set(num) & set(dislike))
    if len(match)==0:
        print(i)
        break

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

while True:
    M = str(N)
    numbers = list(M)
    matchedlist = []
    for a in dislike:
        for b in numbers:
            if a == b:
                matchedlist.append(a)
    
    if matchedlist == []:
        break

    N += 1

print(N)

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

found = False
bad = False
while not found:
    for i in str(n):
        if int(i) in a:
            bad = True
    if not bad:
        found = True
    bad = False
    n += 1

print(n - 1)

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,10*N+1):
    I=list(map(int,str(i)))
    match=list(set(I)&set(D))
    if len(match)==0:
        print(i)
        break
    else:
        pass

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

while True:
    f = True

    for a in map(int, list(str(n))):
        if a in dl:
            f = False

    if f:
        break
    n += 1

print(n)

Solution (Python):
import bisect
n,k=map(int,input().split())
l=list(map(int,input().split()))
nl=list(range(10))
for i in l:nl.remove(i)
ch=int(str(nl[-1])*len(str(n)))<n
if ch and nl[0]==0:
    print(int(str(nl[1])+"0"*(len(str(n)))))
elif ch:
    print(int(str(nl[0])*(len(str(n))+1)))
else:
    ans=""
    for i in range(len(str(n))):
        if int(str(n)[i]) in l:
            ans+=str(nl[bisect.bisect_left(nl,int(str(n)[i]))])
            ans+=str(nl[0])*(len(str(n))-i-1)
            break
        else:ans+=str(n)[i]
    print(ans)

Solution (Python):

l=list(range(10))


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


for x in l2:
  l.remove(x)


l=set(l)


for x in range(1,100001):
  
  y=set(map(int,list(str(x))))

  
  if N<=x and l.issuperset(y):
    print(x)
    break

Solution (Python):

l=list(range(10))


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

ans=''
f=False


for x in l2:
  l.remove(x)


l=set(l)

for x in range(1,1000000):
  y=set(map(int,list(str(x))))
  if N<=x and l.issuperset(y):
    print(x)
    break

Solution (Python):
import collections
import math
import sys
N,K = map(int,input().split())
Ds = list(map(int,input().split()))
for n in range(N,100000):
    check = True
    for d in Ds:
        if str(d) in str(n):
            check = False
            break
    if check ==True:
        print(n)
        break

Solution (Python):
def f(n, d):
    while True:
        for x in d:
            try:
                str(n).index(str(x))
            except ValueError:
                pass
            else:
                break
        else:
            return n
        n = n + 1


nk = list(map(int, input().split()))
n = nk[0]

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

print(f(n, d))

Solution (Python):
n, _ = map(int, input().split(' '))
no_likes = list(map(int, input().split(' ')))

numbers = sorted([i for i in range(10) if i not in no_likes])

for i in range(n, 100000):
    for b in str(i):
        if int(b) not in numbers:
            break
    else:
        print(i)
        break

Solution (Python):
Num = [int(n) for n in input().rstrip().split()]

D = [int(n) for n in input().rstrip().split()]

for i in range(Num[0],100000):
    if len(set([str(n) for n in D]) & set(str(i))) == 0:
        print(int(i))
        break

Solution (Python):
N, K = [int(i) for i in input().split()]
d_li = [int(i) for i in input().split()]
all_digits = set(range(10))
dis_digits = set(d_li)
like_digits = all_digits - dis_digits
like_li = sorted(list(like_digits))

while set([int(i) for i in str(N)]) & dis_digits:
    N += 1
print(N)

Solution (Python):
N, K = map(int, input().split())
D = set(list(map(int, input().split())))
while True:
    int_i = [int(s) for s in list(str(N))]
    set_i = set(int_i)
    if not D & set_i:
        print(N)
        break
    N += 1

Solution (Python):
n,k=map(int, input().split())
l1=map(int,input().split())
l2=[0,1,2,3,4,5,6,7,8,9]
l3=set(l1)^set(l2)
m=str(n)
l4=map(int,set(m))
l4=set(l4)
def check(a,b):
    if (a|b)==a:
        return True
    else:
        return False
while check(l3,l4) is False:
    n=n+1
    m=str(n)
    l4=map(int,set(m))
    l4=set(l4)
print(n)

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


Num1 = []
for i in range(10):
  if(i in D): continue
  else: Num1.append(i)
 

Comb = []
n = len(str(N))
for i in range(n+1):
  Comb.append(Num1)
Comb = list(itertools.product(*Comb))

ans = -1
for i in range(len(Comb)):
  tmp = Comb[i]
  tmp_num = ''
  for j in range(n): tmp_num += str(tmp[j])
  tmp_num = int(tmp_num)
  if(N <= tmp_num):
    ans = tmp_num
    break
    
if(ans == -1):
  for i in range(len(Comb)):
   tmp = Comb[i]
   tmp_num = ''
   for j in range(n+1): tmp_num += str(tmp[j])
   tmp_num = int(tmp_num)
   if(N <= tmp_num):
     ans = tmp_num
     break
print(ans)

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
j=[(True if i in d else False)for i in range(10)]
for i in range(n,10**6):
    s=str(i)
    for h in range(len(s)):
        if j[int(s[h])]:
            break
    else:
        print(s)
        break

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

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

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


temp = N - 1
flg = True
while flg:
    temp += 1
    flg = False
    st = str(temp)
    for i in range(len(st)):
        if st[i] in dl:
            flg = True
print(temp)

Solution (Python):
def irohas_obsession(N: int, K: int, D: list) -> int:
    
    min_not_d = min(d for d in range(10) if d not in D)
    min_not_d_and_not_zero = min(d for d in range(10) if d not in D and d != 0)

    
    nums = []
    while N > 0:
        nums = [N % 10] + nums
        N //= 10

    
    convert_idx = -1
    for i, n in enumerate(nums):
        if n not in D:
            
            continue

        convert_idx = i
        break
    
    for i in range(convert_idx, -1, -1):
        n = nums[i]
        if n > 9:
            n %= 10
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

        for d in range(n, 10):
            
            if d in D:
                
                continue

            nums[i] = d
            break
        else:
            
            for d in range(n, 10):
                if d in D:
                    
                    continue

                nums[i] = d

            
            if i > 0:
                nums[i - 1] += 1
            else:
                nums = [min_not_d_and_not_zero] + nums

    
    nums = [min_not_d if n in D else n for n in nums]

    ret = 0
    digit = 1
    
    for n in reversed(nums):
        ret += n * digit
        digit *= 10

    return ret


if __name__ == "__main__":
    N, K = map(int, input().split())
    D = [int(s) for s in input().split()]
    ans = irohas_obsession(N, K, D)
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)

N, K = map(int, input().split())
D = input().split()
decimal = set(["0","1", "2", "3", "4", "5", "6", "7", "8", "9"]) - set(D)
candidate = []
def dfs(s):
    if len(s) == 0:
        sub_d = decimal - set("0")
        for d in sub_d:
            dfs(s + d)    
    elif len(s) < len(str(N)) + 1:
        if int(s) >= N:
            candidate.append(int(s))
        for d in decimal:
            dfs(s + d)
    else:
        candidate.append(int(s))
        return
dfs("")
print(sorted(candidate)[0])

Solution (Python):


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

while True:
    res = n
    for x in d:
        res = str(res).replace(str(x), "X")
    if "X" in res:
        n += 1
    else:
        print(res)
        exit()

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

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

ans = []
t = 0
for i, dig in enumerate(list(str(N))):
    m = 10
    for cu in can_use:
        sa = cu - int(dig)
        if sa <= m and sa >= 0:
            m = sa
            ans.append(cu)
            if abs(len(list(str(N)))-1-i) == 0:
                break
            t += cu*10**abs(len(list(str(N)))-1-i)
            tmp = t + int(str(can_use[0])*abs(len(list(str(N)))-1-i))
            if tmp >= N:
                print(tmp)
                exit()











if len(ans) < len(list(str(N))):
    min_not0 = can_use[1] if can_use[0] == 0 else can_use[0]
    print(str(min_not0)+str(can_use[0])*len(list(str(N))))
    exit()

print(''.join(map(str, ans[::-1])))

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

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

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

X={0,1,2,3,4,5,6,7,8,9}-D

for i in range(n,100000):
    if set([int(a) for a in str(i)])|X==X:
        print(i)
        break

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

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

n_list = list(str(n))
n_list = [int(num) for num in n_list]

num = {1,2,3,4,5,6,7,8,9,0}

d_set = set(d)
empty = set()



while(1):
  n_list = list(str(n))
  n_list = [int(num) for num in n_list]
  if(set(n_list) & d_set == empty):
    print(n)
    break
  n += 1

Solution (Python):
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,88889):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Solution (Python):
n,k=map(int,input().split())
d=list(map(str,input().split()))
for i in range(n,90000):
  for j in list(str(i).replace(""," ").split()):
    if j in d:
      break
  else:
    print(i)
    break

Solution (Python):

N,K=map(int,input().split())
D=list(map(str,input().split()))
for i in range(10*N):
    Nlist=list(str(N))
    Nlen=len(Nlist)
    flag=0
    for j in range(Nlen):
        if Nlist[j] in D:
            flag=1
            break
    if flag == 0:
        print(int(N))
        break
    N+=1

Solution (Python):
from sys import stdin
input = stdin.readline
N, K = [int(x) for x in input().rstrip().split()]
D = [int(x) for x in input().rstrip().split()]
ok = [x for x in range(10) if x not in D]
tmp = N
while 1:
	for y in str(tmp):
		if int(y) in ok:
			pass
		else:
			break
	else: 
		print(tmp)
		break
	tmp += 1

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

Solution (Python):
n,k=map(int,input().split());d=input().split()
def judge():
  global d,n
  for i in str(n):
    if i in d:return
  print(n)
  exit()
while 1:
  judge()
  n+=1

Solution (Python):
from functools import reduce

def main():
    
    
    
    
    

    
    
    slist = input().rstrip().split(' ')
    N = int(slist[0])
    K = int(slist[1])
    D = input().rstrip().split(' ')

    for n in range(N,100000):
        
        d_flag = False
        tmp_n = list(str(n))
        
        for tmp_char in tmp_n:
            if (str(tmp_char) in D):
                d_flag = True
                break
        if(d_flag == False):
            print(n)
            break
    
if __name__ == '__main__':
    main()

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

for i in range(n,n*100):
    flg=True
    for j in str(i):
        if j in d:
            flg=False
            break;

    if flg:
        print(i)
        break

Solution (Python):
import itertools
import bisect


def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    P = [str(x) for x in range(10) if x not in D]
    num = []
    for i in range(1, len(str(N))+2):
        for c in itertools.product(P, repeat=i):
            num.append(int("".join(c)))
    idx = bisect.bisect_left(num, N)
    print(num[idx])


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
D = input().split()
for n in range(N, 100000):
	if all(d not in str(n) for d in D):
		print(n)
		exit()

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

search = True
while search:
    for i in str(N):
        if not i in D:
            search = False
            continue
        N += 1
        search = True
        break

print(N)

Solution (Python):


















import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, K = s_inpl()
D = inpl()

l = set(range(0, 10))  - set(D)
c = copy.deepcopy(N)
while True:
    ls = set([int(i) for i in list(str(c))])
    if ls.issubset(l):
        print(c)
        break
    c += 1

Solution (Python):



N, _ = input().split()
N = int(N)

dislike_nums = input().split()

def contains_dislike_number(num):
    for n in dislike_nums:
        if n in str(i):
            return True
    return False

for i in range(N, 10*N+1):
    if not contains_dislike_number(i):
        print(i)
        break

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

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

Solution (Python):





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

def is_in_d(s):
	for d in D:
		if d in s:
			return True
	return False
for i in range(100000):
	ans = str(N+i)
	if not is_in_d(ans):
		break

print(ans)

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

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

def detecter(n):
    A = list(str(n))
    for i in A:
        if(int(i) in X):
            return False
    return True

while(not(detecter(n))):
    n += 1
print(n)

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
for i in range(N,100000):
	Ai=str(i)
	if all((str(j) not in Ai)for j in D):
			print(i)
			break

Solution (Python):
n,k = map(int,input().split())
D = set([int(d) for d in input().split()])
num = set([0,1,2,3,4,5,6,7,8,9])
D = list(num - D)
D.sort(reverse=True)
_ = 10**7
def abcC(x, ans):
    if len(x) == len(str(n))+3:
        return ans
    if n <= int(x) < ans:
        ans = int(x)
    elif n > int(x):
        for i in D:
            ans = abcC(x+str(i),ans)
    return ans
        
print(abcC('0',_))

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

d = input().split()

while 1:
    temp = list(str(n))
    for c in d:
        
        if c in temp:
            
            break
    else:
        print(n)
        exit()
    n += 1
    continue

Solution (Python):

N,K=map(int,input().split())
D=list(map(int,input().split()))
E=[0]*10
for d in D:
    E[d]=1

while(1):
    for n in str(N):
        if E[int(n)]==1:
            N+=1
            break
    else:
        break

print(N)

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

def valid(x):
    while x:
        if (x % 10) in list:
            return 0
        x //= 10
    return 1

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

print(cur)

Solution (Python):
n,k=input().split()
n=int(n)
k = int(k)
bl=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
L = [int(x) for x in input().split()]
for i in L:
   x = int(i)
   bl[x]=1
while True:
     s = str(n)
     flag=0
     for i in s:
         if bl[int(i)]==1:
             n = n + 1
             flag = 1
             break
     if flag == 0:
         break
print(n)

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

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

Solution (Python):
import sys
N, K = map(int, input().split())
D = list(input().split())
D = set(D)
for i in range(N, 100 * N):
    if D & set(str(i)):
        continue
    else:
        print(i)
        sys.exit()

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




while 1:
    check = True
    for i in D:
        if i in list(str(N)):
            check = False
            break
    if check:
        break
    
    N += 1

print(N)

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

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

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
a=[]
for i in range(10):
    sum=0
    for x in d:
        if x==i:
            break
        else:
            sum+=1
    if sum==k:
        a.append(i)
a=set(a)
for i in range(n,10*n+1):
    b=[]
    x=len(str(i))
    y=str(i)
    for j in range(x):
        b.append(int(y[j]))
    b=set(b)
    if a>=b:
        print(i)
        break

Solution (Python):
l=[str(x) for x in range(100000)]
n,k=map(int,input().split())
l2=list(map(str,input().split()))
ind=l.index(str(n))
while True:
  a=l[ind]
  f=False
  for x in l2:
    if x in a:
      f=True
  if not f:
    break
  ind+=1
print(a)

Solution (Python):
n,l = map(int,input().split())
x = [ int(i) for i in input().split() ]
a = [ 0 for i in range(10) ]
for i in x:
    a[i] = 1

def check(n):
    s = str(n)
    for i in s:
        if a[int(i)] == 1:
            return False
    return True

while check(n) == False:
    n += 1

print(n)

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


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

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

for i in range(N,100001):
    stri = set(list(str(i)))
    find = True
    for d in D:
        if d in stri:
            find = False
            break
    if find:
        print(i)
        sys.exit()

Solution (Python):
n, k = map(int, input().split())
A = set([int(i) for i in input().split()])
num = set([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) - A

for i in range(n, n * 10 + 1):
    for j in list(str(i)):
        if int(j) not in num:
            break
    else:
        print(i)
        break

Solution (Python):
price, n = [int(i) for i in input().split(' ')]
exclude_nums = [int(i) for i in input().split(' ')]

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

for num in exclude_nums:
    nums.discard(num)

while True:
    safe = True
    for num in str(price):
        if int(num) in nums:
            pass
        else:
            price += 1
            safe = False
            break
    if safe:
        print(price)
        break

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

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

Solution (Python):
n,k=[int(i) for i in input().split()]
d=[i for i in input().split()]
num=[i for i in range(1,10) if (i in d)==False]
def check(number):
    s=str(number)
    result=True
    for i in range(len(s)):
        if s[i] in d:
            result=False
    return result
if check(n):
    print(n)
else:
    while True:
        if check(n+num[0]):
            print(n+num[0])
            break
        else:
            n+=num[0]

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() 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 check(n):
    n = list(map(int,list(str(n))))
    s = 0
    for i in n:
        s += f[i]
    return s == 0
n,k = LI()
d = LI()
f = [0 for i in range(10)]
for i in d:
    f[i] = 1
while 1:
    if check(n):
        print(n)
        quit()
    n += 1

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

CANUSE = [x for x in filter(lambda x: not x in D, range(0,10))]


candidates = []
q = [("")]


while q:
    s = q.pop()
    if len(s) >= 6:
        continue
    if ( int(s) if s != "" else 0 )  >= N:
        candidates.append(int(s))
        continue

    for ch in CANUSE:
        q.append( s+str(ch) ) 

print(min(candidates))

Solution (Python):
def validate(n, d: set) -> bool:
    while n > 0:
        
        r = n%10
        if r in d:
            return False
        n //= 10
    return True


def solve(n, d):
    d = set(d)
    for i in range(n, 10**6):
        if validate(i, d):
            return i
    return -1


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


if __name__ == '__main__':
    assert validate(2000, [1,3,4,5,6,7,8,9])
    assert not validate(1002, [1,3,4,5,6,7,8,9])
    main()

Solution (Python):
N, _ = map(int, input().split())
D = list(map(int, input().split()))
E = [str(i) for i in [0,1,2,3,4,5,6,7,8,9] if i not in D]
E
while not all(n in E for n in str(N)):
    N+=1
print(N)

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

def solve():
    def is_valid(num):
        s_num = str(num)
        for ng in NGs:
            if s_num.count(ng):
                return False
        return True

    
    

    num = BASE

    while not is_valid(num):
        num += 1

    return num

res = solve()
print(res)

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
x=0
p=n
while x==0:
    q=list(str(p))
    x=1
    for y in q:
        if  y in d:
            p+=1
            x=0
            break
print(p)

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

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

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

Solution (Python):
import itertools

N, M = map(int, input().split())
L = list(map(str, input().split()))
tmp = [0 for _ in range(10)]
seq = []

for i in range(10 ** 5):
    tmp = str(i)
    flag = True
    for j in range(len(tmp)):
        if tmp[j] in L:
            flag = False
        
    if i >= N and flag == True:
        res = i
        break

        
print(res)

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

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

def str_check(string):
  string=str(string)
  for i in string:
    if int(i) not in nums:
      return False
  return True

for i in range(1,100000):
  if str_check(i)==True and n<=i:
    print(i)
    exit()

Solution (Python):



def main():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    like_numbers = [i for i in range(10) if i not in d]
    digit_count = len(list(map(str, list(str(n)))))
    digit = [0] * digit_count
    ans = list()

    def dfs(count):
        if count == digit_count:
            return ans.append(int(''.join(map(str, digit))))

        for like_number in like_numbers:
            digit[count] = like_number
            dfs(count + 1)

    dfs(0)

    if max(ans) >= n:
        print(min([a for a in ans if a >= n]))
    else:
        digit_count += 1
        digit = [0] * digit_count
        dfs(0)
        print(min([a for a in ans if a >= n]))


if __name__ == '__main__':
    main()

Solution (Python):
import itertools

def main():
    n, _ = map(int, input().split())
    d = [int(s) for s in input().split()]
    p = [i not in d for i in range(10)]

    print(solve(n, p))

def solve(n, p):
    def check(i):
        if i == 0:
            return True
        if not p[i % 10]:
            return False
        return check(i // 10)

    for i in itertools.count(n):
        if check(i):
            return i

main()

Solution (Python):


N,K=map(int, raw_input().split(" "))   
D=map(int, raw_input().split(" "))   
keta=len(str(N))
strN=str(N)
ans1=""
for x in range(keta-1):
    p=int(strN[keta-x-1])
    d=0
    for dd in range(10):
        if dd not in D:
            d=dd
            break
    ans1=str(d)+ans1
candidate=int(strN[0])
def ok(n):
    s=str(n)
    for ss in s:
        if int(ss) in D: return False
    return True
while True:
    if ok(candidate) and int(str(candidate)+ans1)>=N: 
        break
    candidate+=1

ans1=str(candidate)+ans1
if ok(N):
    print(N)
else:
    print(int(ans1))

Solution (Python):
def contains_digit(n: int, d: set):
    flag = False
    while n > 0:
        flag = flag or (n % 10 in d)
        n //= 10
    return flag

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

for i in range(N, N*10):
    if not contains_digit(i, D):
        print(i)
        break

Solution (Python):
price, num = input().split(" ")
dislike = input().split(" ")
for i in range(int(price), 100000):
    if set(dislike) & set(str(i)):
        continue
    else:
        print(i)
        break

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

for i in range(n, 100000):
  if bool(set([int(x) for x in str(n)]) & d_set ) is False:
    print(n)
    break
  n += 1

Solution (Python):
n=input()[:-2]
s=sorted(set(range(10))-set(map(int,input().split())))
s=[str(i)for i in s]
if all(i in s for i in n):
  print(n)
  exit()
f=0
t=''
for i in n:
  if f:
    t+=s[0]
  elif i in s:
    t+=i
  else:
    for j in s:
      if int(j)>int(i):
        t+=str(j)
        f=1
        break
    else:
      break
else:
  print(t)
  exit()
t=(s[0]*(s[0]!='0')or s[1])+s[0]*len(n)
print(t)

Solution (Python):
n=input()[:-2]
s=sorted(set(range(10))-set(map(int,input().split())))
s=[str(i)for i in s]
if all(i in s for i in n):
  print(n)
  exit()
f=0
t=''
for i in n:
  if f:
    t+=s[0]
  elif i in s:
    t+=i
  else:
    for j in s:
      if int(j)>int(i):
        t+=str(j)
        f=1
        break
    else:
      break
else:
  print(t)
  exit()
t=(s[0]*(s[0]!='0')or s[1])+s[0]*len(n)
print(t)

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

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

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

    i += 1

Solution (Python):
N,K = map(int,input().split())
D  = {int(n) for n in input().split()}
for j in range(N,N*10):
    if N <= j:
        L = {int(result) for result in str(j)}
        if D.isdisjoint(L):
            D_love = j
            break    
print(D_love)

Solution (Python):
N,K =map(int,input().split())
D =[i for i in input().split()]
s =True
while True:
  Ns =str(N)
  for i in D:
    if i in Ns:
      s =False
  if not s:
    s =True
    N += 1
  else:
    break
print(N)