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):
def problem_c():
    N, K = map(int, input().split())
    D = list(map(str, input().split()))
    numbers = {str(i) for i in range(10)}
    availables = set(numbers) - set(D)

    for i in range(N, 100000):
        nums = set(str(i))
        if nums <= availables:
            print(i)
            return


problem_c()

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())
D=list(map(str, input().split()))


for i in range(N,10**9):
    flg = True
    for j in str(i):
        if j in D:
            flg = False
    if(flg):
        print(i)
        exit()

Solution (Python):
price, _ = map(int, input().split())
hate = list(input().split())

while sum([i in hate for i in list(str(price))]) > 0:
    price += 1

print(price)

Solution (Python):
N, K = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
D = [1 if i not in d else 0 for i in range(10)]
for a in range(N,10*N+1):
    for b in str(a):
        if D[int(b)] == 0:
            break
    else:
        print(a)
        break

Solution (Python):
import sys
 
input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))
sys.setrecursionlimit(10**6)

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
    
    

dfs(N)

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

for i in range(100001):
   yen = n + i
   if set(list(str(yen))) & set(dl):
      continue
   else:
      print(yen)
      import sys
      sys.exit()

Solution (Python):
N,K=[int(c) for c in input().split()]
D=0
for c in input().split():
  D|=(1<<int(c))
while(1):
  d=0;
  for c in str(N):
    d|=1<<int(c)
  if(d&D==0):
    print(N)
    exit()
  N+=1;

Solution (Python):
def solve(target: int, dislike_numbers: set) -> int:
    for i in range(target, target * 10):
        used_numbers = set(int(n) for n in str(i))
        if not used_numbers.intersection(dislike_numbers):
            return i

target, n = map(int, input().split())
values = map(int, input().split())
print(solve(target, set(values)))

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

for i in range(n, 100001):
    x = list(str(i))
    flag = True
    for j in x:
        if int(j) in a:
            continue
        else:
            flag = False
            break
    if flag is True:
        print(i)
        exit()

Solution (Python):
import bisect
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(0,10)) ^ set(D)
length = len(str(N))

for l in range(length, length+2):
  comb = [int("".join(map(str, a))) for a in product(like_num, repeat=l)]
  ind = bisect.bisect_left(comb, N)
  if len(comb) != ind and comb[ind] >= N:
    print(comb[ind])
    exit()

Solution (Python):
from itertools import product

N, K = map(int, input().split())
D = map(int, input().split())
like_num = set(range(10)) ^ set(D)
length = len(str(N))

for i in range(length, length+2):
  for x in product(like_num,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=N:
          print(d)
          exit()

Solution (Python):
import math
import fractions

n, k = map(int, input().split())
d = [i for i in input().split()]
i = n
while 1:
    flag = 1
    for j in d:
        if j in str(i):
            i += 1
            flag = 0
            break
    if flag:
        print(i)
        break

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

for i in range(N,10**6):
  ng = 0
  str_i = str(i)
  for s in str_i:
    if s in D:
      ng = 1
      break
  if ng == 0:
    print(i)
    break

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

for i in range(n,10**6+1):
    if any(x in set(str(i)) for x in d):
        continue
    else:
        print(i)
        exit()

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

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

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

for i in range(n, 10*n+1):
    num = list(str(i))
    for j, n in enumerate(num):
        if n in d:
            break
        if j == len(num)-1:
            print(i)
            exit()

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

d = list(map(int, input().split()))
a = []
for i in range(10):
  if i not in d:
    a.append(str(i))
ans = n
while True:
  b = str(ans)
  if all([i in a for i in b]):
    break
  ans += 1
print(ans)

Solution (Python):
N, X = map(int, input().split())
arr = list(input().split())
ans = 0
for i in range(N,10**7):
    flg = True
    s = str(i)
    for k in s:
        if str(k) in arr:
            flg = False
            break
    if flg:
        print(i)
        exit()

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

while any(int(x) in d for x in str(n)):
  n += 1
print(n)

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

while any(int(x) in d for x in str(n)):
    n += 1

print(n)

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

d = set([str(_d) for _d in d])

ans = n
while True:
    f = True
    a = str(ans)
    for _a in a:
        if _a in d:
            f = False
    if f:
        print(ans)
        break
    else:
        ans += 1

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

num = list(map(str, range(10)))
for k in range(K):
  num.remove(D[k])
for I in range(N, 100000):
  if all([II in num for II in str(I)]):
    print(I)
    break

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

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

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


def dfs(num, pos, target):
    if pos == target:
        if num >= N:
            print(num)
            sys.exit()
        return
    for i in st:
        dfs(num * 10 + i, pos + 1, target)


Len = len(str(N))
dfs(0, 0, Len)
dfs(0, 0, Len+1)

Solution (Python):
ip = input().split()
N = int(ip[0])

K = int(ip[1])
Dinput = input().split()
Ds = []
for i in range(K):
    Ds.append(Dinput[i])

boolean = False
n = N
while boolean == False:
    str_n = list(str(n))
    for d in range(K):
        if Ds[d] in str_n:
            boolean = False
            break
        else:
            boolean = True
    if boolean == False:
        n += 1
    
print(n)

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

while True:
	for s in str(N):
		if A.count(int(s)): break
	else:
		break
	N += 1
print(N)

Solution (Python):
n,a =map(int,input().split())
s=list(map(str,input().split()))
while set(str(n))&set(s):
    n+=1
print(n)

Solution (Python):
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, K = map(int,input().split())
    D = set(list(input().split()))
    for k in range(N,100001):
        s = str(k)
        f = 0
        for e in s:
            if e in D:
                f = 1
                break
        if f == 0:
            print(s)
            exit(0)

if __name__ == '__main__':
    main()

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

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

print(n)

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

n = N
while True:
    s = str(n)
    S = set(list(s))
    for c in S:
        if c in D:
            break
    else:
        break
    n += 1
print(n)

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

def isAvailable(x):
    for c in str(x):
        if int(c) in d:
            return False
    return True

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

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

while True:
    s = str(n)
    for x in d:
        if x in s:
            break
    else:
        break
    n += 1

print(n)

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

payment = n
while True:
    tmp = str(payment)
    for t in tmp:
        if t in dislikes:
            break
    else:
        break
    payment += 1
print(payment)

Solution (Python):
N,M=map(int,input().split())
T=list(map(int,input().split()))




L=[]
for i in range(10):
    if(not T.count(i)):
        L.append(i)

l=len(str(N))+1
MIN=10**10

def calc(st):
    global MIN
    st=str(st)
    if(len(st)>l):return 0
    for num in L:
        t=calc(st+str(num))
        if(int(t)>=N):
            MIN=min(MIN,int(t))
    if(st!=""):
        if(int(st)>=N):
            MIN=min(int(st),MIN)
    return (MIN)

print(calc(str()))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
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)]
mod = 1000000007


n, k = LI()
D = set(LI())
for i in range(n, 100000):
    if not set([int(j) for j in str(i)]) & D:
        print(i)
        break

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
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)]
mod = 1000000007


n, k = LI()
D = set(range(10)) - set(LI())
for i in range(n, 100000):
    if set([int(j) for j in str(i)]) <= D:
        print(i)
        break

Solution (Python):
from itertools import *

if __name__=="__main__":
    n,k = map(int,input().split(' '))
    d = list(map(int,(input().split(' '))))
    d = [i for i in range(10) if i not in d]
    ans = 1e10
    keta = len(str(n))
    for k in range(1,keta+2):
        for perm in product(d,repeat=k):
            num = 0
            for v in perm:
                num = 10*num+v
            if n <= num and num < ans:
                ans = num
    print(ans)

Solution (Python):
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for v in list(map(int, input().rstrip('\n').split())):
        d[str(v)]
    for i in range(n, 10 ** 10):
        s = str(i)
        b = True
        for v in s:
            if v in d:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    solve()

Solution (Python):
import itertools
n, k = map(int, input().split())
d = set(list(map(int, input().split())))
inzero = False
if 0 in d:
    inzero = True
    d -= set([0])
can_use = set([0,1,2,3,4,5,6,7,8,9]) - d
can_use = list(can_use)

ans = 10**6
def check(i):
    global ans
    x = int("".join(list(map(str, i))))
    if inzero:
       pp = list(str(x))
       if '0' in pp:
           return
    if x >= n:
        ans = min(ans, x)
def dfs(Sequence):
    if len(Sequence) == len(str(n)) + 1:
        check(Sequence)
    else:
        for i in can_use:
            dfs(Sequence + [i])
dfs([])
print(ans)

Solution (Python):
import sys

n, k, *dislikes = sys.stdin.read().split()
n = int(n)
dislikes = set(dislikes)

def main():
    i = n
    while True:
        if set(str(i)) & dislikes:
            i += 1
            continue
        return i

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

Solution (Python):
import sys
from string import digits
from itertools import product
from bisect import bisect_left as bi_l

n, k, *dislikes = sys.stdin.read().split()

def main():
    likes = sorted(set(digits) - set(dislikes))
    cand = product(likes, repeat=len(n))
    *cand, = map(lambda x: int(''.join(x)), cand)
    cand.sort()
    res = bi_l(cand, int(n))
    if res < len(likes) ** len(n):
        return cand[res]
    
    if likes[0] == '0':
        ans = likes[1] + '0' * len(n)
    else:
        ans = likes[0] * (len(n)+1)
    return int(ans)

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

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

p = n
while any(de in str(p) for de in d):
    p += 1
print(p)

Solution (Python):
def main():
    N, K = list(map(int, input().split()))
    D = set(map(int, input().split()))
    ok_set = set([i for i in range(0,10)]) - D
    ok_list = list(ok_set)
    

    def is_ok(num):
        ans = True
        for si in str(num):
            n = int(si)
            if n not in ok_list:
                ans = False
        return ans

    for ni in range(N, 10 ** 9):
        if is_ok(ni):
            print(ni)
            break



if __name__ == "__main__":
    main()

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

    OK_N = set([i for i in range(0, 10)]) - D
    OK_N = list(OK_N)

    l1 = [str(i)for i in OK_N]
    for _ in range(len(str(N)) - 1):
        tmp_l = []
        for li in l1:
            
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l1 = tmp_l

    l2 = [str(i)for i in OK_N]
    for _ in range(len(str(N))):
        tmp_l = []
        for li in l2:
            
            for ni in OK_N:
                s = li + str(ni)
                tmp_l.append(s)
        l2 = tmp_l

    lc = []
    for li in l1:
        lc.append(int(li))
    for li in l2:
        lc.append(int(li))
    

    lc.sort()
    for li in lc:
        if li >= N:
            print(li)
            break

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product
n,k=map(int,input().split())
a=list(map(int,input().split()))
ls=[0,1,2,3,4,5,6,7,8,9]
nm=[]
for i in ls:
  if i not in a:
    nm.append(i)
b=[]
for i in product(nm,repeat=5):
  b.append(10000*i[0]+1000*i[1]+100*i[2]+10*i[3]+i[4])
  b.append(1000*i[0]+100*i[1]+10*i[2]+i[3])
  b.append(100*i[0]+10*i[1]+i[2])
  b.append(10*i[0]+i[1])
  b.append(i[0])
b.sort()
for i in b:
  if i>=n:
    print(i)
    break

Solution (Python):
n, k = map(int, input().split())
d = set(map(str, input().split()))
numbers = {str(i) for i in range(10)}
available = numbers - d
for i in range(n, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

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):
from bisect import bisect_left
from itertools import product
N, K = map(int, input().split())
D = [int(i) for i in input().split()]
ary = []
for n in range(10):
    if n not in D:
        ary.append(str(n))

l = []
for it in product(ary, repeat=len(str(N))):
    n = int(''.join(it))
    l.append(n)
    if n > 10000:
        break
l.sort()
i = bisect_left(l, N)
if i < len(l):
    print(l[i])
else:
    print(int((ary[0] if ary[0] != '0' else ary[1]) + ary[0]*(len(str(N)))))

Solution (Python):
def iroha(n):
    flag = False
    tmp = list(map(int, list(set(list(str(n))))))
    for i in tmp:
        if D.count(i) != 0:
            return flag
    flag = True
    return flag


N, K = map(int, input().split())
D = list(map(int, input().split()))
while True:
    if iroha(N):
        break
    N += 1
print(N)

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

Solution (Python):
N,K = map(int, input().split())
D = input().split()
ans = N
while True:
    tmp = str(ans)
    for t in tmp:
        if t in D:
            break
    else:
        break
    ans += 1
print(ans)

Solution (Python):
N  ,K = map(int,input().split())
D = list(input())
now = N
s = set(list(str(now)))
d = set(D)
while s & d != set():
    now += 1
    
    s = set(list(str(now)))
print(now)

Solution (Python):
import sys
N,K,*vD=map(int,sys.stdin.buffer.read().split())
for x in range(N,10**5):
	if any(int(d) in vD for d in str(x)):
		continue
	print(x)
	break

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,1000000):
    f=1
    for k in d:
        if str(k) in str(i):
            f=0
            break
    if f:
        print(i)
        exit()

Solution (Python):
N,K = map(int,input().split())
D = list(input())
for i in range(N,10**5):
    si = str(i)
    f = True
    for digit in si:
        if digit in D:
            f = False
            continue
    if f:
        print(i)
        exit()

Solution (Python):


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


D = input().split()




for n in range(N,10*N):
    
    
    
    
    if set(str(n)).isdisjoint(set(D)):
        print(n)
        
        break

Solution (Python):
a,b=map(int, input().split())
s = list(map(str,input().split()))
num=int(a)
D = set(s)
numbers = {str(i) for i in range(10)}
available = numbers - D

for i in range(a,100000):
  nums = set(str(i))
  if nums <= available:
    print(i)
    break

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


for i in range(N, N * 10 + 1):
    if not any([s in D for s in str(i)]):
        print(i)
        exit()
print('err')

Solution (Python):
N, K = input().split()
K = int(K)
NL = list(map(int, N[::-1]))

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

min_d = min([i for i in range(10) if i not in D])

mod_idx = -1
i = 0
while len(NL) > i:
    n = NL[i]
    for j in range(n, 10):
        if j in D:
            NL[i] += 1
            mod_idx = i
        else:
            break

    if NL[i] >= 10:
        if i + 1 >= len(NL):
            NL.append(0)
        NL[i + 1] += 1
        mod_idx = i + 1
    i += 1

if mod_idx >= 0:
    for i in range(0, mod_idx):
        NL[i] = min_d
print(*reversed(NL), sep='')

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

Solution (Python):
import sys

def hantei(array,n):
  s = str(n)
  for i in range(len(s)):
    if int(s[i]) in array:
      return False
  
  return True

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

while True:
  if hantei(d,n):
    print(n)
    sys.exit()
    
  n += 1

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

for i in range(n,100000):
    f=0
    for j in d:
        if str(i).find(j) >= 0:
            break
        else:
            f+=1
    if f == k:
        print(i)
        sys.exit()

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

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in range(N, 100000):
    a=i//10000
    if bool((a not in D) or i <10000):
        b=i//1000 - 10*a
        if bool((b not in D) or i <1000):
            c=i//100 - 100 * a - 10 * b
            if bool((c not in D) or i < 100):
                d= i//10 - 1000 * a - 100*b - 10*c
                if bool((d not in D) or i <10):
                    e=i%10
                    if e not in D:
                        ans.append(i)
print(ans[0])

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

ans = n
while 1:
    a = str(ans)
    count = 0
    for i in range(len(a)):
        if a[i:i+1] in d:
            count += 1
    if count == 0:
        break
    else:
        ans += 1
print(ans)

Solution (Python):
N, _ = input().split(' ')
N = int(N)

dislikes = input().split(' ')


while True:
    n_str = str(N)
    if not any([n in dislikes for n in n_str]):
        print(n_str)
        break
    N += 1

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

Solution (Python):
from sys import stdin

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(str,stdin.readline().rstrip().split()))

for i in range(n,99999):
    yen = str(i)
    frag = 0
    for j in yen:
        if j in li:
            frag = 1
    if frag == 0:
        print(yen)
        exit()

Solution (Python):
import sys

n, k = map(int, input().split())
d = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}-set(int(x) for x in input().split()))

while True:
  ans = n
  while ans > 0:
    key = ans%10
    if key in d:
      ans = ans//10
      if ans == 0:
        print(n)
        sys.exit()
      continue
    else:
      break
  n += 1

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

Solution (Python):
NLinput = input()
NLinput = [int(x) for x in NLinput.split()]

N = NLinput[0]
L = NLinput[1]
input_D = input()
D_list = set([int(x) for x in input_D.split()])

bill = N
flag = True

while flag:
    temp = set([int(x) for x in list(str(bill))])
    if len(list(temp&D_list))==0:
        flag = False
    else:
        bill += 1
print(bill)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    D=set(map(int,input().split()))
    for i in range(n,100000):
        flag=True
        for s in str(i):
            if(int(s) in D):
                flag=False
        if(flag):
            print(i)
            return
resolve()

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

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

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

while len(d.intersection(set(list(str(n)))))>0:
    n+=1

print(n)

Solution (Python):
n, k = map(int, input().split())
A = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - set(input().split())
while True:
  s = set(str(n))
  if s <= A:
    print(n)
    break
  n += 1

Solution (Python):
n, k = map(int, input().split())
l=set(input().split())
while True:
    if set(str(n)) & l == set():
        print(n)
        exit()
    n+=1

Solution (Python):
n,k=map(int,input().split())
L = set(input().split())
while True:
  if set(str(n)) & L == set():
    print(n)
    exit()
  n += 1

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

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

while(True):
    if(not({int(c) for c in str(n)} & d)):
        break
    n += 1

print(n)

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

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

    while 1:
        if len(set(list(str(n))) & d)==0:
            print(n)
            exit()
        else:
            n +=1

if __name__=='__main__':
    main()

Solution (Python):
nums = input().split()
s_N = str(nums[0])
i_N = int(nums[0])
K = int(nums[1])
nums2 = input().split()
count = 0

while count < K:
    
    x = nums2[count]
    if x in s_N:
        i_N += 1
        s_N = str(i_N)
        count = 0
    else:
        count += 1

print(s_N)

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

i=n
while True:
    h=list(str(i))
    for u in h:
        if u in d:
            break
    else:
        print(i)
        break
    i+=1

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n,k=map(int,input().split())
D=set(input().split())
while True:
    ns=str(n)
    for ni in ns:
        if ni in D:
            break
    else:
        print(n)
        exit()
    n+=1
    continue

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

while 1:

    strN=str(N)
    flag=0
    for n in range(len(strN)):
        if strN[n] in D:
            flag=1
            break
    if flag:
        N+=1
    else:
        print(N)
        exit()

Solution (Python):
import string
n,k =[int(i) for i in input().split()]
not_use=[int(i) for i in input().split()]
use=[int(i) for i in string.digits if int(i) not in not_use]

def check(n):
    for i in str(n):
        if(int(i) in not_use):
            return False
    return True


x=n-1
while True:
    x+=1
    if(check(x)==True):
        print(x)
        exit()

Solution (Python):
NK=input().split()
N=int(NK[0])
K=int(NK[1])
D=input().split()

while (True):
    flag=0
    for i in range(K):
        if(D[i] in str(N)):
            flag=1
    if(flag==0):
        print(N)
        break
    else:
        N+=1

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

for i in range(N*10):
    if i >= N:
        s = str(i)
        for j in s:
            if int(j) in D:
                break
        else:
            print(s)
            break

Solution (Python):
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0] for _ in range(prv_len-i)]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i:] = [nums[j]] + [nums[0] for _ in range(len(N)-i-1)]
  
  i -= 1
print(''.join([str(n) for n in N]))

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N):
    if i >= N:
      s = str(i)
      for j in range(len(s)):
        if int(s[j]) in D:
          break
      else:
        print(i)
        return 0
solve()

Solution (Python):
n,k=map(int,input().split())
D=list(map(int,input().split()))
L=D
for i in range(9*n):
    for s in str(n+i):
        if int(s) in D:
            break
    else:
        print(n+i)
        exit()

Solution (Python):
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0
 
solve()

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

for i in range(N,100000):
  j=0
  si=list(str(i))
  for k in si:
    if int(k) in D:
      j=1
  if j==0:
    print(i)
    exit()

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

Solution (Python):
n,k = map(int, input().split())
d = list(input().split())
ans = n
while True:
    flag = False
    a = list(str(ans))
    for dx in d:
        if dx in a:
            flag = True
    if flag:
        ans +=1
    else:
        print(ans)
        exit()

Solution (Python):
def main():
    N, K = map(int, input().split())
    D = list(str(x) for x in input().split())

    while True:
        strN = str(N)
        flg = 0
        for i in strN:
            if i in D:
                flg = 1
        if flg == 0:
            print(N)
            break
        else:
            N += 1
        
if __name__ == '__main__':
    main()