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):


import io
import sys
import math

def format_multi_line_answer(lst):
    ans = ""
    ans += f"{len(lst)}\n"  
    for y in lst:
        ans += f"{y}\n"
    return ans

def solve(n,k_set):
    
    for i in range(n, sys.maxsize):
        s = set(str(i))
        
        if s & k_set == set():
            return i

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

    
    ans = str( solve(n,k_set) )
    
    
    print(ans)
    return ans
        

_DEB = 0   

_INPUT = """\
1000 8
1 3 4 5 6 7 8 9
"""
_EXPECTED = """\
2000

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")


if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()
    D = in_nl()

    num = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - set(D)

    for n in range(N, N * 10 * 1):
        if set(map(int, str(n))) <= num:
            break

    print(n)


if __name__ == '__main__':
    main()

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

i = N
while 1:
  S = str(i)
  flag = 1
  for s in S:
    if s in Ds:
      flag = 0
      break
  if flag == 1:
    print(i)
    exit()
  i += 1

Solution (Python):
n,_=map(int,input().split())
m=set(input().split())
while True:
    for i in str(n):
        if i in m:
            n+=1
            break
    else:
        break
print(n)

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

for price in range(n, 10000000):
    if len(set(list(str(price))) - D) == len(set(list(str(price)))):
        print(price)
        break

Solution (Python):
def has_no(s, digits):
    for ch in s:
        if ch in digits:
            return False
    return True

def digit():
    N, K = [int(n) for n in input().split()]
    digits = input().split()

    for i in range(N, N*10):
        s = str(i)
        if has_no(s, digits):
            print(s)
            break

digit()

Solution (Python):

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

availbale_numbers = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    availbale_numbers.remove(i)

for i in range(N,99999):
    if(set(str(i)) <= set([str(a) for a in availbale_numbers])):
        print(i)
        break

Solution (Python):

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

availbale_numbers = [0,1,2,3,4,5,6,7,8,9]

for i in D:
    availbale_numbers.remove(i)

for item1 in availbale_numbers:
    if(N <= int(('').join([str(item1)]))):
         print(('').join([str(item1)]))
         exit()

for item1 in availbale_numbers:
    for item2 in availbale_numbers:
        if(N <= int(('').join([str(item1),str(item2)]))):
            print(('').join([str(item1),str(item2)]))
            exit()

for item1 in availbale_numbers:
    for item2 in availbale_numbers:
        for item3 in availbale_numbers:
            if(N <= int(('').join([str(item1),str(item2),str(item3)]))):
                print(('').join([str(item1),str(item2),str(item3)]))
                exit()

for item1 in availbale_numbers:
    for item2 in availbale_numbers:
        for item3 in availbale_numbers:
            for item4 in availbale_numbers:
                if(N <= int(('').join([str(item1),str(item2),str(item3),str(item4)]))):
                    print(('').join([str(item1),str(item2),str(item3),str(item4)]))
                    exit()

Nmin = min(availbale_numbers)
if(Nmin==0):
    print(f'{availbale_numbers[1]}{Nmin}{Nmin}{Nmin}{Nmin}')
else:
    print(f'{Nmin}{Nmin}{Nmin}{Nmin}{Nmin}')

Solution (Python):

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

p_list=[]
ok_list=[]

hate_list.append(10)
s=0
for x in hate_list:
    while x>s:
        ok_list.append(s)
        s+=1
    s+=1
ok_list.append(10)




ndgts=[]
while n>0:
    ndgts.append(n%10)
    n//=10

flag=0 
for y in reversed(ndgts):
    if flag>0:
        p_list.append(0)
        continue
    for x in range(11-k):
        if y==ok_list[x]:
            p_list.append(x)
            break
        elif y< ok_list[x]:
            p_list.append(x)
            flag=1
            break



p_list.reverse()
for x in range(len(p_list)-1):
    if p_list[x]==10-k:
        p_list[x]=0
        p_list[x+1]+=1

if p_list[-1]==10-k:
    p_list[-1]=0
    if ok_list[0]==0:
        p_list.append(1)
    else:
        p_list.append(0)
payment=0

for x in reversed(p_list):
    payment=10*payment + ok_list[x]
print(payment)

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

T = True
while T:
  x = str(N)
  p = 0
  for i in range(len(x)):
    if x[i] in D:
      p = 1
  
  if p == 0:
    T = False
  else:
    N += 1

print(N)

Solution (Python):
import io,sys
sys.setrecursionlimit(10**6)

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

    while True:
        temp = n
        num = []
        while temp > 0:
            num.append(temp%10)
            temp//=10
        
        flag = True
        for i in num:
            if i in D:
                flag = False
                break
        if flag:
            print(n)
            sys.exit()
        else:
            n+=1
main()

Solution (Python):



import sys


def input():
    return sys.stdin.readline().strip()


def _main():
    n, k = input().split()
    x = set(input())

    n_s = set(n)

    n_i = int(n)
    while True:
        if x & n_s:
            n_i += 1
            n_s = set(str(n_i))
        else:
            print(n_i)
            break


if __name__ == "__main__":
    _main()

Solution (Python):

import sys,math,itertools
input = sys.stdin.readline
n, k = map(int, input().split())
d = [int(_) for _ in input().split()]
d_set = set(d)
d_all = set(range(10))
d_use = [str(a) for a in list(d_all - d_set)]
keta = int(math.log10(n))+1


temp = 100000
for i in list(itertools.product(d_use, repeat=keta+1)):
  a = int(''.join(list(i)))
  if (a>=n)&(a<temp):
    temp = a
for i in list(itertools.product(d_use, repeat=keta)):
  a = int(''.join(list(i)))
  if (a>=n)&(a<temp):
    temp = a

print(temp)

Solution (Python):

import sys,math,itertools
input = sys.stdin.readline
n, k = map(int, input().split())
d = [int(_) for _ in input().split()]
d_set = set(d)
d_all = set(range(10))
d_use = [str(a) for a in list(d_all - d_set)]
keta = int(math.log10(n))+1
l1 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta+1))]
l2 = [int(''.join(list(a))) if int(''.join(list(a)))>=n else 100000 for a in list(itertools.product(d_use, repeat=keta))]

print(min(min(l1), min(l2)))

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
while True:
    flg = True
    lis = list(str(N))
    for i in lis:
        if int(i) in D:
            flg = False
    if flg == True:
        print(N)
        exit()
    N += 1

Solution (Python):
import sys

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

nums = [i for i in range(10)]
canuse = []

for i in nums:
    if i not in d:
        canuse.append(i)

for i in range(n,n*10):
    x = 0
    for j in str(i):
        if int(j) not in canuse:
            break
        else:
            x += 1
            if x == len(str(i)):
                print(i)
                sys.exit()

Solution (Python):
n, k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ans = n
f = False
while True:
    for dd in d:
        if str(dd) in str(ans):
            f = True
            break
    if not f:
        break
    f = False
    ans += 1

print(ans)

Solution (Python):
n, k = map(int, input().split())
*excluded_digits, = input().split()
i = 0
while i < n or any(ch in excluded_digits for ch in str(i)):
    i += 1
print(i)

Solution (Python):
def check(s,l):
	for i in s:
		if i in l:
			return False
	return True

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

for s in [str(i) for i in range(n,100000)]:
	if check(s,l):
		print(s)
		break

Solution (Python):
   
def has_no2(s, digits):
    for ch in s:
        if ch in digits:
            return False
    return True

def main2():
    N, K = [int(x) for x in input().split()]
    digits = ''.join(input().split())

    for s in [str(i) for i in range(N, 100000)]:
        if has_no2(s, digits):
            print(s)
            break

main2()

Solution (Python):
def has_no(s, digits):
    for ch in s:
        if digits.get(ch):
            return False
    return True

def main():
    N, K = [int(x) for x in input().split()]
    digits = {str(x): True for x in input().split()}

    for s in [str(i) for i in range(N, 100000)]:
        if has_no(s, digits):
            print(s)
            break
   
main()

Solution (Python):
import sys

N, K = map(int, input().split())
D = list(map(int, sys.stdin.readline().rsplit()))

for i in range(N, 100000):
    for d in D:
        if str(d) in str(i):
            break
    else:
        print(i)
        exit()

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
dp=[0]*10
for i in range(K):
  dp[D[i]]=1
for i in range(N,10**6+1):
  a=str(i)
  flag=True
  for j in range(len(a)):
    if dp[int(a[j])]==1:
      flag=False
      break
  if flag:
    print(i)
    exit()

Solution (Python):
def main():
    from collections import deque
    N,K = map(int,input().split())
    D = list(set(range(10)) - set(map(int,input().split())))
    D.sort()
    targets = deque(D)
    while True:
        t = targets.popleft()
        if N <= t:
            print(t)
            return
        t *= 10
        for d in D:
            targets.append(t+d)
main()

Solution (Python):
n,k,*a=map(int,open(0).read().split())
for i in range(n,10**6):
    if all(str(j) not in str(i) for j in a):
        print(i)
        exit()

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

for i in range(N, 100000):
    for j in D:
        if j in str(i):
            break
    else:
        print(i)
        break

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

for i in range(n, 100000):
    for j in d:
        if j in str(i):
            break
    else:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
d = set(map(int, input().split()))
s = set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
dd = s - d

for i in range(n, 100001):
    ss = set([int(i) for i in list(str(i))])
    if dd >= ss:
        print(i)
        break

Solution (Python):
n,k=map(int,input().split())
d=set(map(int,input().split()))
i=n
while True:
    temp=i
    flag=1
    while temp>0:
        if temp%10 in d:
            flag=0
            break
        temp//=10
    if flag:
        print(i)
        break
    i+=1

Solution (Python):



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


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



for j in range(n,100000):
    h = str(j)
    u=0
    for s in h:
        if int(s) in t:
            u+=1
            break
    if u==0:
        print(h)
        break

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

for i in range(n, 100000):
    for j in str(i):
        if int(j) in d:break 
    else:
        print(i)
        exit()

Solution (Python):
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
d = list(map(int, input().split()))
d = set(d)
while True:
    found = True
    cur = n
    while cur:
        if cur % 10 in d:
            found = False
            break
        cur //= 10
    if found:
        exit(print(n))
    n += 1

Solution (Python):
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList:
        if n[i] < y:
            n[i] = y
            j = i+1
            while j < len(n):
                n[j] = okList[0]
                j += 1

            break
    else:
        if i - 1 < 0:
            n = [0] + n
            i += 1
        n[i - 1] += 1
        j = i
        while j < len(n):
            n[j] = okList[0]
            j += 1
print(int("".join(list(map(str, n)))))

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque

    n, k = map(int, readline().split())
    d = list(map(int, readline().split()))
    e = [str(i) for i in range(10) if i not in d]

    que = deque([i for i in e if i != "0"])

    while True:
        x = que.popleft()
        if int(x) >= n:
            print(x)
            sys.exit()

        for y in e:
            que.append(x+y)


if __name__ == '__main__':
    main()

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

ans = 99999
for i in range(99999, N-1, -1):
    for j in range(5):
        if 10**j > i:
            continue
        if (i//(10**j))%10 in D:
            break
    else:
        ans = i

print(ans)

Solution (Python):

N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    hantei = True
    for i in D:
        if str(i) in str(N):
            hantei = False
    if hantei==False:
        N+=1
    else:
        print(N)
        break

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

dislike = set(list(map(int, input().split())))

next_map = {}
min_digit = 0
for i in range(10):
    for j in range(i,10):
        if j not in dislike:
            if i == 0:
                min_digit = j
            next_map.update({ i : j })
            break
        next_map.update({ i : min_digit })
max_digit = max(next_map.values())

num = len(list(N))
count = num
cand = []
for n in list(N):
    n = int(n)
    if n in dislike:
        n_ = next_map[n]
        cand.append(n_)
        count -= 1
        cand.extend(count*[min_digit])
        break
    else:
        cand.append(n)
        count -= 1
cand = int("".join(list(map(str, cand))))
if int(N) <= cand:
    print(cand)
else:
    if min_digit == 0:
        next_min = next_map[1]
        cand = [next_min] + num * [0]
    else:
        cand = (num + 1) * [min_digit]
    cand = int("".join(list(map(str, cand))))
    print(cand)

Solution (Python):
a = input().split()
tg = a[0]
ok_nums = set(["1","2","3","4","5","6","7","8","9","0"])
ng_nums = set(input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1

Solution (Python):
a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1

Solution (Python):
a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
intg = int(tg)
while intg > rt:
  if ok_nums >= set(d for d in str(i)):
    rt = i
  else:
    i+=1

print(rt)

Solution (Python):
a = input().split()
tg = a[0]
ok_nums = set(str(i) for i in range(10))
ng_nums = set(i for i in input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
intg = int(tg)
while intg > rt:
  if ok_nums >= set(d for d in str(i)):
    rt = i
  else:
    i+=1

print(rt)

Solution (Python):
D = [i for i in range(10)]
N,K = map(int,input().rstrip().split(" "))
A = list(map(int,input().rstrip().split(" ")))
flag = True
for i in range(N,10 ** 6 + 1):
    flag = True
    for i2 in range(6):
        if i >= 10 ** i2 and (i // (10 ** i2)) % 10 in A:
            flag = False
            break
    if flag:
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
dat = list(map(str,input().split()))
for i in range(n, 1000001):
    s = str(i)
    did = True
    for j in range(len(s)):
        if s[j] in dat:
            did = False
    if did:
        break
print(i)

Solution (Python):
n,k=map(int,input().split())
d=list(input().split())
for num in range(n,100001):
    num=str(num)
    ok=True
    for c in num:
        if c in d:
            ok=False
    if ok:
        print(num)
        exit()

Solution (Python):
n,k = map(int,input().split())
d = list(map(int,input().split()))
for i in range(n,100001):
    s = list(str(i))
    sw = 0
    for t in s:
        for j in range(k):
            if int(t) == d[j]:
                sw = 1
                break
        if sw == 1:
            break
    if sw == 0:
        print(i)
        break

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

for i in range (N, 100000): 
	k = str(i)
	counter = 0
	for j in range (0, K):
		if k.find(l[j]) >= 0:
			counter+=1
	if counter == 0:
		print(i)
		exit()

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

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

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

Solution (Python):
N, K = map(int, input().split())
P = list(map(int, input().split()))
numbers = [0,1,2,3,4,5,6,7,8,9]
use = []
for i in numbers:
  if not i in P:
    use.append(i)

ul = []
if 0 in use:
  for u5 in [0,use[1]]:
    for u4 in use:
      for u3 in use:
        for u2 in use:
          for u1 in use:
            ul.append(u5*10000 + u4*1000 + u3*100 + u2*10 + u1)
else:
    for u4 in use:
      for u3 in use:
        for u2 in use:
          for u1 in use:
            ul.append(use[0]*10000 + u4*1000 + u3*100 + u2*10 + u1)
            ul.append(u4*1000 + u3*100 + u2*10 + u1)
            ul.append(u3*100 + u2*10 + u1)
            ul.append(u2*10 + u1)
            ul.append(u1)
ul.sort()
for r in ul:
  if N <= r:
    print(r)
    break

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

for n in range(N, N*10):
    for s in str(n):
        if s in d:
            break
    else:
        print(n)
        break

Solution (Python):
n,k=map(int,input().split())
d=set([int(x) for x in input().split()])
for i in range(n,100001):
    flag=True
    for j in str(d):
        if j in str(i):
            flag=False
            break
    if flag==True:
        print(i)
        exit()

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

for i in range(n,100000):
  
  res = 0
  for j in str(d):
    if j in str(i):
      res += 1
  if res == 0:
    print(i)
    exit()

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


while True:
    s_n = str(n)
    for num in d:
        flag = True
        if num in s_n:
            flag = False
            break
    if flag is True:
        break
    n += 1

print(n)

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

while True:
    check = True
    for x in arr:
        if str(x) in str(n):
            check = False
    if check:
        break
    n += 1
print(n)

Solution (Python):
N, K = map(int, input().split())
D = {i for i in range(10)} - set(map(int, input().split()))
for i in range(N, 100000):
    if all(j in D for j in map(int, str(i))):
        print(i)
        break

Solution (Python):

N,K=map(int,input().split())
out=N
N=str(N)
a = list(map(int, input().split()))
while 1<2:
    N1=N
    i=0
    for i in range(len(a)):
        if str(a[i]) in N:
            N=int(N) 
            N+=1
            N=str(N)
    if N1==N:
        break

print(N)

Solution (Python):
import sys
N, K = map(int, input().split())
d = list(map(str, input().split()))
D = set(d)
for i in range(N, 1000000):
    S = set(str(i))
    T = True
    for s in S:
        if s in D:
            T = False
            break
    if T:
        print(i)
        break

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

nums = []
for i in range(10):
  if i not in d: nums.append(i)

for i in range(len(str(n)), 6):
  for j in product(nums, repeat=i):
    t = ""
    if j[0] != 0:
      for k in j:
        t += str(k)
      if int(t) >= n:
        print(t)
        exit()

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

for i in range(N,10*N):
    tmp = list(str(i))
    for j in tmp:
        if j in D:
            break
    else:
        print(''.join(tmp))
        break

Solution (Python):
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, K = mi()
    D = set(mi())
    while True:
        if set(map(int, str(N))) & D:
            N += 1
        else:
            print(N)
            return
if __name__ == '__main__':
    main()

Solution (Python):
N , L = map(int,input().split())
nols = list(map(str,input().split()))

for i in range(10*N):
    pri = N + i
    pri = str(pri)
    if any(x in pri for x in nols):
        continue
    else:
        print(pri)
        break

Solution (Python):
import sys
input = sys.stdin.readline




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)


from collections import deque

q=deque()
q.extend(a)
for i in range(len(a)):
    if int(a[i])>=n:
        print(a[i])
        sys.exit()

while True:
    qq=q.popleft()
    
    for item in a:
        qqq=qq+item
        
        if int(qqq)>=n:
            print(qqq)
            sys.exit()
        q.append(qqq)

Solution (Python):
import sys
input = sys.stdin.readline




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

a=list(map(str, [0,1,2,3,4,5,6,7,8,9]))
n,k=map(int, input().split())
d=list(map(str, input().split()))
for item in d:
    a.remove(item)


from collections import deque

q=deque()
q.extend(a)
for i in range(len(a)):
    if int(a[i])>=n:
        print(a[i])
        sys.exit()

while True:
    qq=q.popleft()
    
    for item in a:
        qqq=qq+item
        
        if int(qqq[::-1])>=n:
            print(qqq[::-1])
            sys.exit()
        q.append(qqq[::-1])

Solution (Python):
import sys
n,k=map(int,input().split())
d=list(map(int,input().split()))
allowed=set()
for i in d:
  allowed.add(i)
for i in range(n,10**7):
  b=str(i)
  c=set()
  for j in range(len(b)):
    c.add(int(b[j]))
  if allowed.intersection(c)==set():
    print(i)
    sys.exit()

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

bn = sorted(list((set([0,1,2,3,4,5,6,7,8,9]) - D_list)))
res = 0
for v4 in bn:
    money = v4
    if money >= N:
        print(money)
        exit()

for i3 in bn:
    v3 = i3 * 10
    for v4 in bn:
        money = v3+v4
        if money >= N:
            print(money)
            exit()

for i2 in bn:
    v2 = i2 * 100
    for i3 in bn:
        v3 = i3 * 10
        for v4 in bn:
            money = v2+v3+v4
            if money >= N:
                print(money)
                exit()

for i1 in bn:
    v1 = i1 * 1000
    for i2 in bn:
        v2 = i2 * 100
        for i3 in bn:
            v3 = i3 * 10
            for v4 in bn:
                money = v1+v2+v3+v4
                if money >= N:
                    print(money)
                    exit()

for i0 in bn:
    v0 = i0 * 10000
    for i1 in bn:
        v1 = i1 * 1000
        for i2 in bn:
            v2 = i2 * 100
            for i3 in bn:
                v3 = i3 * 10
                for v4 in bn:
                    money = v0+v1+v2+v3+v4
                    if money >= N:
                        print(money)
                        exit()

Solution (Python):
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, k = LI()
	D = set(LI())
	for num in range(n,10**5):
		if set(map(int,list(str(num)))) & D == set():
			print(num)
			break


if __name__ == '__main__':
    main()

Solution (Python):
N, K = map(int, input().split())
d = list(map(str, input().split()))
like = [ str(i) for i in range(10)]
like = list(set(like) ^ set(d))
Ans = 0

while( Ans == 0):
    if set(list(str(N))) <= set(like):
        print(N)
        Ans +=1
        exit()
    N += 1

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

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

print(ans)

Solution (Python):
amount, num = map(int, input().split())

hated_digit = list(map(str, input().split()))

while True:
    check = 0
    for hd in hated_digit:
        if hd not in str(amount):
            check += 1

        else:
            amount += 1
    if check == num:
        print(amount)
        break

Solution (Python):
amount, num = map(int, input().split())

hated_digit = list(map(str, input().split()))

while True:
    check = 0
    for hd in hated_digit:
        if hd not in str(amount):
            check += 1

        else:
            amount += 1

    if check == num:
        print(amount)
        break

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

Solution (Python):


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

paid = n
while True:
    st = set(int(x) for x in str(paid))
    l = len(st)
    if len([x for x in st if x not in D]) == l:
        print(paid)
        break
    paid += 1

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

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

Solution (Python):
n, _ = map(int, input().split())
arr = list(map(str, input().split()))

can_use = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
can_use -= set(arr)

price = set(str(n))

while price - can_use:
    n += 1
    price = set(str(n))

print(n)

Solution (Python):
n,k=map(int,input().split())
D = list(map(str,input().split()))
x = n
while True:
  y = str(x)
  for i in range(len(y)):
    if y[i] in D:
      break
  else:
    ans = x
    break
  x += 1
print(ans)

Solution (Python):
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=str(n)
flag=False
while flag==False:
    flag=True
    for j in l:
        if s.count(str(j))!=0:
            s=int(s)
            s+=1
            s=str(s)
            flag=False
            break
print(s)

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

suki =list({0,1,2,3,4,5,6,7,8,9} - set(d))
suki.sort()

result=[]
pay=0
def dfs(pos, pay):
  if pay >= n:
    result.append(pay)
    return result
  elif pos >= 5:
      return '99999'
  
  for i in suki:
    dfs(pos+1, pay*10+i)

dfs(0, 0)
print(min(result))

Solution (Python):
def main():
    n, k = list(map(int, input().split()))
    D = set(input().split())
    ans = n
    while not set(list(str(ans))).isdisjoint(D):
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n,k = map(int, input().split())
d = list(input().split())
while True:
    c=0
    for m in range(k):
        if d[m] in str(n):
            c+=1
    if c==0:
        print(n)
        break
    else:
        n+=1

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

Solution (Python):
def hantei(num,list):
    score = 0
    for i in range(len(list)):
        if list[i] in str(num):
            score = +1
    return score                

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

dislike = list(map(str,input().split()))

while True:
    if hantei(N,dislike) == 0:
        break
    N = N + 1
print(N)

Solution (Python):
from collections import Counter


def ok(n, D):
    
    counter = Counter(str(n))
    for d in D:
        if counter[str(d)] > 0:
            return False
    return True


def main():
    N, K = list(map(int, input().split(' ')))
    D = list(map(int, input().split(' ')))
    while not ok(N, D):
        N += 1
    print(N)



if __name__ == '__main__':
    main()

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

while set(list(str(n))) & d != set():
    n += 1

print(n)