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 sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, K = map(int, input().split())
    D = [str(i) for i in input().split()]
    ans = 0

    for m in range(N, 10**6):
        if canbuy(N, D, m):
            ans = m
            break

    print(m)

def canbuy(N, D, m):
    m = str(m)

    for d in D:
        if m.find(str(d)) != -1:
            return False

    return True


if __name__ == '__main__':
    solve()

Solution (Python):
import itertools
a=set([0,1,2,3,4,5,6,7,8,9])
n,_=map(int,input().split())
b=map(int,input().split())
l=len(str(n))
c=set(b)^a
for i in range(l,l+2):
    for x in itertools.product(c,repeat=i):
        d=''.join(map(str,x))
        if int(d)>=n:print(d);exit()

Solution (Python):

from itertools import product

N, K = [int(_) for _ in input().split()]
D = set([int(_) for _ in input().split()])
valid = list(set(range(10)) - D)

x = set()
for r in range(1,6):
    for p in product(valid, repeat=r):
        x.add(int(''.join([str(i) for i in p])))

for n in sorted(x):
    if n >= N:
        print(n)
        break

Solution (Python):
n, k = map(int, input().split())
dislikes = list(map(int, input().split()))
m = n
while True:
    m = list(str(m))
    l = []
    for p in m:
        if int(p) not in dislikes:
            l.append(p)
            continue
        else:
            m = int(''.join(m))+1
            break
    if len(l) >= len(str(n)):
        if int(''.join(l))>=n:
            break
print(''.join(m))

Solution (Python):
def run_code(N, K, ds):

    dislike_digits_set = set(i for i in ds)
    avail_digits = [i for i in range(10) if i not in dislike_digits_set]
    avail_min = avail_digits[0]

    def get_next_digit(d):
        last = 10
        for ad in (avail_digits + [last]):
            if ad >= d:
                if ad == last:
                    return (1, avail_min)
                else:
                    return (0, ad)

    def fill_last_kth_digits(n_digits, d, k):
        n = len(n_digits)
        for i in range(k):
            n_digits[n - i - 1] = d
        return n_digits

    def to_num(n_digits):
        num = 0
        n = len(n_digits)
        for i in range(n):
            num += n_digits[i] * 10**(n-i-1)
        return num

    def to_digits(num):
        return [int(i) for i in str(num)]

    def search_nearest_larger(num):
        n_digits = to_digits(num)
        n = len(n_digits)

        for i in range(n):
            d_in = n_digits[i]
            inc, d_out = get_next_digit(d_in)
            if inc == 0 and d_in == d_out:
                continue
            if inc > 0:
                num += 10**(n-i)
                n_digits = fill_last_kth_digits(to_digits(num), avail_min, n-i)
                return search_nearest_larger(to_num(n_digits))
            else:
                n_digits[i] = d_out
                return to_num(fill_last_kth_digits(n_digits, avail_min, n-i-1))

        return to_num(n_digits)

    return search_nearest_larger(N)


N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
res = run_code(N, K, ds)
print(res)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n,k = LI()
    s = set(LS())
    for i in range(n,n*100):
        t = set(_ for _ in str(i))
        if not (t & s):
            return i

    return 0


print(main())

Solution (Python):
N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(N, 100000+1):
    if set(str(i)) & D == set():
        print i
        exit()

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

def check(num):
    for i in range(len(num)):
        for j in d:
            if int(num[i])==j:
                return False
    return True

while(not check(str(n))):
    n+=1
print(n)

Solution (Python):


def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        f = True
        for a in str(n):
            if int(a) not in usable_num:
                f = False
                break
        if f: break
        n += 1
    print(n)

if __name__ == '__main__':
    main()

Solution (Python):


def main():
    num = [0,1,2,3,4,5,6,7,8,9]
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    usable_num = list(set(num) - set(d))

    while True:
        if len(set(map(int, str(n))) - set(usable_num)) == 0:
            break
        else:
            n += 1
    print(n)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
from itertools import combinations


def func(i, d, now, use, st):
    if i >= d:
        st.append(now)
        return

    for x in use:
        func(i + 1, d, now + str(x), use, st)


def solve():
    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)

    for i in range(len(str(n)), len(str(n)) + 2):
        st = []
        func(0, i, "", use, st)
        for x in sorted(st):
            if int(x) >= n:
                return x


def main():
    print(solve())


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,raw_input().split())
d=set(map(int,raw_input().split()))
chk=set([str(i) for i in range(10) if i not in d])
while 1:
    tmp=set(str(n))
    if len(tmp&chk)==len(tmp):
        print n
        break
    n+=1

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




for i in d:
    ablenum.remove(i)



flag_bigdigit = -1


for i in range(len(lis_n)):
    _i = len(lis_n) - i - 1
    if(int(lis_n[_i]) > max(ablenum)):
        flag_bigdigit = _i
        break


if(flag_bigdigit != -1):
    flag_increaseDights = 1
    
    for i in range(flag_bigdigit-1, 0):
        
        if(int(lis_n[i]) < max(ablenum)):
            flag_increaseDights = 0
            break
else:
    flag_increaseDights = 0



ans = ""

if(flag_increaseDights == 1):
    for i in range(len(lis_n)+1):
        
        if(i == 0):
            mnum = min(ablenum)
            if(mnum == 0):
                mnum = ablenum[1]
            ans += str(mnum)
        
        else:
            mnum = min(ablenum)
            ans += str(mnum)

else:
    flag_over = 0
    for i in range(len(lis_n)):
        if(flag_over == 0):
            mnum = min(ablenum)
            
            j = 0
            while mnum < int(lis_n[i]):
                
                j += 1
                mnum = ablenum[j]
            if(mnum > int(lis_n[i])):
                flag_over = 1
            ans += str(mnum)
        else:
            mnum = min(ablenum)
            ans += str(mnum)

print(ans)

Solution (Python):
import sys

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

for i in xrange(N * 10):
    if i >= N:
        temp = i
        isCorrect = True
        while temp > 0:
            if (temp % 10) in D:
                isCorrect = False
                break
            else:
                temp /= 10
        if isCorrect:
            print i
            break

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

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

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

for i in range(N, 10*N):
	for k in range(len(str(i))):
		if str(i)[k] in S:
			flag = False
			break
		else:
			flag = True
			continue
		
	if flag:
		print(i)
		break

Solution (Python):
N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
    candi.remove(d)

def decide(i):
    if i >= len(N):
        return ''
    for c in candi:
        if N[i] == c:
            return c + decide(i+1)
        elif N[i] < c:
            return c + candi[0] * (len(N) - i - 1)

if candi[-1] * len(N) >= N:
    print decide(0)
else:
    print (candi[0] if candi[0] != '0' else candi[1]) + candi[0] * len(N)

Solution (Python):

N, L = [int(i) for i in input().split()]
D = sorted([i for i in input().split()])

for i in range(N, 100000):
    if all([s not in D for s in list(str(i))]):
        print(i)
        break

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(100000):
    for x in str(N):
        if x in D:
            break
    else:
        print N
        break
    N += 1

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

while True:
        if set(map(int,list(str(N)))) & D_set:
                N += 1
        else:
                break

print(N)

Solution (Python):
N,K = map(int,raw_input().split(" "))
A = map(int,raw_input().split(" "))
n = [int(c) for c in str(N)]
len_n = len(n)
digits = []
for i in range(10):
    if not(i in A):
        digits.append(i)


def need_big_keta():
    if n[0] <  digits[-1]:
        return False
    i=0
    while i < len_n and n[i] == digits[-1] :
        i+=1
    if i==len_n:
        return False
    if n[i] < digits[-1]:
        return False
    return True

if not need_big_keta():
    for i in range(N,int("9"*len_n)+1):
        j = i
        flag = True
        while j:
            if not j%10 in digits:
                flag = False
                break
            j/=10
        if flag:
            print i
            break
elif 0 in digits:
    print str(digits[1])+"0"*len_n
else:
    print str(digits[0])*(len_n+1)

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

d = input().split()

def check(c):
    for i in d:
        if str(c).count(i): return False
    return True

count = N
while True:
    if check(count): break
    count += 1
print(count)

Solution (Python):
class IrohasObsession:
	def getMinimumValue(self,n,k,d):
		nums=list(set(d)^set([0,1,2,3,4,5,6,7,8,9]))
		for i in range(100000):
			digits=[int(str(n)[i]) for i in range(len(str(n)))]
			flag=1
			for j in range(len(digits)):
				if not digits[j] in nums: flag=0
			if flag: print n; return
			n+=1
		print -1

if __name__ == "__main__":
	n,k=[int(i) for i in raw_input().split()]
	d=[int(i) for i in raw_input().split()]
	i=IrohasObsession()
	i.getMinimumValue(n,k,d)

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

dp = [True]*10
for e in D:
	dp[e] = False

def calc(s):
	res = True
	for c in s:
		if not dp[int(c)]:
			res = False
			break
	return res

while True:
	if calc(str(N)):
		break
	else:
		N += 1

print(N)

Solution (Python):
N,K=map(int,input().split())
Ds=list(input().split())
Di=list(map(int,Ds))
nex=[1]*10
for i in reversed(Di):
    nex[i-1]=nex[i]+1

def check(n):
    ns = str(N)
    for nss in ns:
        if nss in Ds:
            return False
    return True

def next(i):
    global N
    ns='{0:0>5}'.format(N)
    t=nex[int(ns[i])]
    pp=int(ns[i])+t
    if pp >=10:
        t=t-10
        N+=t*(10**(4-i))
        next(i-1)
    else:
        N+=t*(10**(4-i))

while not check(N):
    next(4)
print(N)

Solution (Python):
def solve():
    n, k = map(int, input().split())
    d = set(input().split())
    while True:
        s = str(n)
        for x in d:
            if x in s:
                break
        else:
            print(s)
            break
        n += 1


def main():
    solve()


if __name__ == '__main__':
    main()

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

def check(num,D):
    numStr = str(num)
    for i in range(len(numStr)):
        if int(numStr[i]) in D:
            return False
    return True

n = int(N)
for i in range(n,100000):
    if check(i,D):
        print( i )
        break

Solution (Python):
import re


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        
        return input()

    @staticmethod
    def read_from_input():
        n, k = IO_for_Contest.read_n_int(2)
        return n, IO_for_Contest.read_n_int(k)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
            int,
            re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    n, d = IO_for_Contest.read_from_input()
    print(min_value_can_pay(n, d))


def min_value_can_pay(n, d):
    ints_can_be_used = think_ints_can_be_used(d)
    queue = []
    for i in ints_can_be_used:
        queue.append(i)
    while len(queue) > 0:
        j = queue.pop(0)
        if j >= n:
            return j
        if j == 0:
            continue
        for i in ints_can_be_used:
            queue.append(j * 10 + i)


def think_ints_can_be_used(d):
    ints = list(range(10))
    for i in d:
        ints.remove(i)
    return ints

if __name__ == '__main__':
    
    
    solve()

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

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

Solution (Python):

def check_number(ans):
    ans = map(int,list(str(ans)))
    for i in range(len(ans)):
        for j in range(K):
            if ans[i]==number[j]:
                return 0
    return 1

if __name__ == '__main__':
    N,K = map(int,raw_input().split())
    number = map(int,raw_input().split())

    ans = N
    count = 0
    while(count == 0):
        count = check_number(ans)
        if (count == 0):
            ans += 1

    print ans

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

for x in range(N, N * 10):
    if all(d not in str(x) for d in D):
        print(x)
        break

Solution (Python):
N, K = map(int, raw_input().split())
D = map(str, raw_input().split())
while True:
    if any(l in D for l in str(N)):
        N += 1
    else:
        print N
        break

Solution (Python):



n,k=map(int,raw_input().split())
d=raw_input().split()

while True:
 if all(x not in str(n) for x in d):
  res=n
  break
 n+=1
 
print res

Solution (Python):
N, K = map(int, input().split())
oknums = set(range(10)) - set(map(int, input().split()))

def can(ans):
	digits = map(int, list(str(ans)))
	for d in digits:
		if not d in oknums:
			return False
	return True

ans = N
while True:
	if can(ans):
		print(ans)
		break
	ans += 1

Solution (Python):
import sys
S, K = input().split()
Bad = list(map(int, input().split()))
OK = sorted(set(range(10)) - set(Bad))
NotZero = sorted(set(OK) - set([0]))

if any(d > str(OK[-1]) for d in S):
    print(str(NotZero[0]) + str(OK[0]) * len(S))
    sys.exit()

count = [0] * 10
for c in str(S):
    count[ord(c) - ord('0')] += 1
greater = 0
ans = []


def can(i, d):
    c = str(d)
    if i == 0 and d == 0 and len(S) > 1:
        return 0
    if not greater and c < S[i]:
        return 0
    if c > S[i]:
        return 1
    for b in range(10):
        if count[b] > 0 and b > OK[-1]:
            return 0
    return 1

for i in range(len(S)):
    count[ord(S[i]) - ord('0')] -= 1
    for d in OK:
        if can(i, d):
            if str(d) > S[i]:
                greater = 1
            ans.append(d)
            break

print("".join(str(a) for a in ans))

Solution (Python):
S, K = map(int, input().split())
Bad = list(input().split())

while 1:
    if all(d not in str(S) for d in Bad):
        print(S)
        break
    S += 1

Solution (Python):
import itertools
ini = int(input().split(" ")[0])
try:
    negaset = [int(x) for x in input().split(" ")]
except :
    print (ini)
    exit()
okset = sorted([str(i) for i in range (10) if i not in negaset]) 


for p in [int("".join(j)) for j in itertools.chain.from_iterable (itertools.product(okset,repeat = i)  for i in range (len(str(ini)),len(str(ini))+2) )]:
    if p >= ini:
        print(p)
        break

Solution (Python):
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())
n = N
while True:
    s = str(n)
    if all(str(d) not in s for d in D):
        print n
        break
    n += 1

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

for i in range(n,100000):

    if set(str(i)).issubset(digits):
        print(i)
        break

Solution (Python):
n, k = map(int, input().split())
dislike = input().split()
i = 0
while True:
    money = str(n + i)
    if len(set(money).intersection(dislike)) == 0:
        print(money)
        break
    i += 1

Solution (Python):
N, K = map(int, raw_input().split())
D = raw_input().split()
while any(s in D for s in str(N)):
    N += 1
print N

Solution (Python):



def main():
    N, K = map(int, input().split())
    D = input().split()
    i = N
    while True:
        if len(set(str(i)).intersection(D)) == 0:
            print(i)
            break
        i += 1

if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())
Ds = input().split()
for v in range(N, N*10 + 1):
    strv = str(v)
    for d in Ds:
        if d in strv:
            break
    else:
        print(v)
        break

Solution (Python):
def no_dislike_number(num, D):
    for digit in num:
        if digit in D:
            return False
    return True
    
    
    
    

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

Solution (Python):


mojir=input()
hyo=mojir.split(' ')

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

mojir=input()
hyo=mojir.split(' ')
D=[int(mono) for mono in hyo]

kouho=N

def usecheck(gaku):
    gakustr=str(gaku)
    keta=len(gakustr)
    dame=None
    for idx in range(0,keta,1):
        if gakustr[idx] in hyo:
            dame=idx
            break

    if dame == None:
        return None
    else:
        return (keta-dame)


while True:

    dameketa=usecheck(kouho)
    if dameketa == None:
        break

    kouho=(kouho//(10**(dameketa-1)) +1)*(10**(dameketa-1))

print(kouho)

Solution (Python):
import itertools
N, K = map(int, raw_input().split())
d = map(int, raw_input().split())
d = set(d)
ok = set(range(10)) - d
ok = sorted(list(ok))
ok = [str(i) for i in ok]
i = 1
while True:
    for ele in itertools.product(ok, repeat=i):
        if int("".join(list(ele))) >= N:
            print "".join(list(ele))
            exit()
    i += 1

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

for x in range(N, 100000):
    for y in D:
        if y in str(x):
            break
    else:
        print(x)
        break

Solution (Python):






import math
line=raw_input().rstrip().split(' ')
N=int(line[0])
K=int(line[1])
Disto=raw_input().rstrip().split(' ')
Tru=True
while(Tru):
	Tru=False
	for args in Disto:
		for i in range (len(str(N))):
			if str(N)[i]==args:
				N+=1
				Tru=True
print N

Solution (Python):
N, L = map(int, input().split())
D = input().split()
ans = N
while 1:
    s = str(ans)
    f = 1
    for i in D:
        if i in s : f = 0
    if f : break
    ans += 1
print(ans)

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

D = map(int, raw_input().split())

for i in range(N, 1000000):

  flag = 0

  for j in D:
    if str(j) in str(i):
      flag = 1
      break

  if flag == 0:
    print i
    exit()

Solution (Python):
import itertools,math,bisect,pprint,sys

n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()

Solution (Python):
cond = [int(n) for n in input().split(" ")]
exclude = {n for n in range(10)}
answer = ""
mo = {str(n) for n in input().split(" ")}
exclude = exclude - mo
for n in range(cond[0],100000):
    for m in [n for n in str(n)]:
        if m in mo:
            break
    else:
        print(n)
        break

Solution (Python):
def no_dislike_number(num, D):
    for dislike in D:
        if dislike in num:
            return False
    return True

MAX = 10000
N, K = map(int, input().split())
D = input().split()
num = N
while(True):
    if no_dislike_number(str(num), D):
        print(num)
        break
    num += 1

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

l = map(int, raw_input().split())
flag = False

while flag == False:
	flag = True
	t = n
	while t > 0:
		m = t % 10
		if m in l:
			flag = False
			break
		t = t / 10
	n += 1

print n - 1

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

n, k = read()
d = set(read())

nset = set(map(int, str(n)))
while nset.intersection(d):
    n += 1
    nset = set(map(int, str(n)))
print(n)

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


for i in range(n,10**7):
    ans=set(str(i))

    for j in ans:
        if j in d:
            break
    else:
        print(i)
        exit()

Solution (Python):
import sys

l = raw_input().split()
N = int(l[0])
K = int(l[1])

a = raw_input().split()

like={}

for i in range(10):
    if str(i) in a:
        like.setdefault(i,False)
    else:
        like.setdefault(i,True)
    

while(True):
    ok = True
    num_str = str(N)
    for s in num_str:
        if like[int(s)] is False:
            if(ok): N += 1
            ok = False
            continue

    if(ok):
        print N
        sys.exit()

Solution (Python):
N, _ = [int(x) for x in input().split()]
D = set(range(10)) - set([int(x) for x in input().split()])
n = [int(x) for x in list(str(N))]

i = 0
while i < len(n):
    if n[i] not in D:
        cand = {x for x in D if x > n[i]}
        if len(cand) > 0:
            n[i] = min(cand)
            for j in range(i + 1, len(n)):
                n[j] = 0
            i += 1
        elif i > 0:
                n[i - 1] += 1
                n[i] = 0
                i -= 1
        else:
            n = [1] + [0] * len(n)
    else:
        i += 1

print(''.join([str(x) for x in n]))

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

ans = n
f = 0
while True:
    ansstr = list(str(ans))
    l = len(ansstr)
    cnt = 0
    for i in range(l):
        if ansstr[i] in d:
            break
        else:
            cnt += 1
            if cnt == l:
                f = 1
                break

    if f:
        break

    ans += 1

print(ans)

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

while True:
    current_digits = set(str(n))
    if current_digits & d:
        n += 1
    else:
        break

print(n)

Solution (Python):
N, K = map(int, raw_input().split())
D = "".join(raw_input().strip().split())
i = N
while True:
    flag = True
    for c in str(i):
        if c in D:
            flag = False
    if flag:
        print i
        break
    i += 1

Solution (Python):

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

while True:
    flag = True
    for x in D:
        if str(x) in str(N):
            flag = False
            break
    if flag:
        break
    N += 1

print N

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

while True:
    S = str(N)
    t = 0
    for x in S:
        if x not in D:
            t += 1
    if t == len(S):
        print(S)
        break
    else:
        N += 1

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

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