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):
from itertools import product

def generator(ls, length):
    for i in product(*(ls for i in range(length))):
        yield "".join(i)

def solve(ls, n):
    for i in generator(ls, len(n)):
        if n <= i:
            return i
    if ls[0] == "0":
        return ls[1] + "".join(ls[0] for i in range(len(n)))
    return "".join(ls[0] for i in range(len(n) + 1))


if __name__ == "__main__":
    n, k = input().split()
    ls = {chr(i) for i in range(ord("0"), ord("0") + 10)}
    ls.difference_update(set(input()))
    ls = sorted(ls)
    print(solve(ls, n))

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

Solution (Python):
n,k = map(int,input().split())
d = list(map(str,input().split()))
flg = True
while flg:
    l = list()
    n_s = str(n)

    for i in n_s:
        if i in d:
            break
    else:
        print(n)
        flg = False
        break
    n = n +1
else:
    print(n)

Solution (Python):
def m():
    def is_included(i,d):
        s = str(i)
        for j in d:
            if str(j) in s:
                return True
        return False
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    for i in range(n, n*10):
        if not is_included(i,d):
            return i
    return 0
print(m())

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


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)
      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()))
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 = input().split()

for ans in range(N,N*10+1):
    ch_n = str(ans)
    cnt = 0
    for c in ch_n:
        cnt += 1
        if c in D:
            break
        if cnt == len(ch_n):
            print(ans)
            exit()

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

    for i in range(N, N*10):
        if len(set(list(str(i))) & set(D)) == 0:
            print i
            break

main()

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

ans = 99999
for i in range(n, n*10):
    if set(str(i)) & d == set():
        ans = i
        break
print(ans)

Solution (Python):
N, K = map(int, input().split())
d = set([int(i) for i in input().split()])
while True:
    e = {int(i) for i in str(N)}
    if d & e == set({}): break
    N+=1
print(N)

Solution (Python):
N,K = map(int, input().split())
hate = [i for i in input().split()]
j = 0
k = 0
while j >= 0:
  k = 0
  for nums in hate:
    if nums in str(N):
      k += 1
    else:
      pass
  if k == 0:
    break
  else:
    N += 1

print(N)

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

    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)
    
if __name__ == "__main__":
    main()

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

    i = 0
    while True:
        S = str(N)
        f = True
        for s in S:
            if s in D:
                f = False
                break
        if f:
            break
        N += 1
    print(N)
    
if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
d = set(input().split())
ans=10000
for i in range(n, n*10):
  if set(str(i)) & d == set():
    ans=i
    break
print(ans)

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

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

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

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

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

    price = N
    while True:
        a = False
        for x in D:
            if str(x) in str(price):
                a = True
                break
        if not a:
            break

        price += 1

    print(price)


if __name__ == '__main__':
    main()

Solution (Python):
def find_next_valid_digit(d, bad_nums):
    next_digit = d
    while True:
        valid = True
        for c in str(next_digit):
            if int(c) in bad_nums:
                valid = False
                break
        if valid:
            break
        else:
            next_digit += 1
    return next_digit

if __name__ == '__main__':
    n, k = list(map(int, input().split(' ')))
    bad_nums = list(map(int, input().split(' ')))
    n_str = str(n)
    cur_result = 0
    for i in range(len(n_str)):
        most_significant_digit = int(n_str[i])
        if most_significant_digit in bad_nums:
            basis = cur_result * 10 + most_significant_digit
            cur_result = find_next_valid_digit(basis, bad_nums)
            num_digits_to_fill = (len(n_str) - i - 1)
            num_to_fill = find_next_valid_digit(0, bad_nums)
            if num_digits_to_fill > 0:
                cur_result = (cur_result * (10**num_digits_to_fill)) + int(str(num_to_fill) * num_digits_to_fill)
            break
        else:
            cur_result = cur_result * 10 + most_significant_digit

    print(cur_result)

Solution (Python):
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,10*n+1):
    judge=True
    num=list(str(i))
    num=map(int,num)
    if set(num)&set(d):
        judge=False
    if judge:
        print(i)
        exit()

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

    for i in range(n, 90000):
        for j in str(i):
            if int(j) in d:
                break

        else:
            print(i)
            break


if __name__ == '__main__':
    main()

Solution (Python):
x,n=[int(i) for i in input().split()]
a=[i for i in input().split()]
f=0
while True:
  for i in set(list(str(x))):
    if i in a:
      break
  else:
    print(x)
    break
  x+=1

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

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

Solution (Python):
def c_iroha_obsession(N, K, D):
    for ans in range(N, 10 * N + 1):
        for digit in str(ans):  
            if int(digit) in D:  
                break
        else:  
            break
    return ans
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_iroha_obsession(N, K, D))

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

Solution (Python):
def check(d, x):
    x = str(x)
    for xx in x:
        if int(xx) not in d:
            return False
    return True
    
n, k = map(int, input().split())
d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(map(int, input().split()))

i = n
while 1:
    if check(d, i):
        break
    i += 1
print(i)

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

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

    for i in range(10):
        if i not in D:
            min_ = i
            break

    ans = []
    apnd = ans.append
    num, top, i = N, 0, 0
    while num > 0:
        while num % 10 in D:
            num += 1
            top = i
        num, m = divmod(num, 10)
        apnd(m)
        i += 1

    ans[0:top] = [min_] * top
    print(*ans[::-1], sep='')

main()

Solution (Python):
N, K = map(int, input().split(' '))
hate = list(map(int, input().split(' ')))
allow = set([0,1,2,3,4,5,6,7,8,9]) - set(hate)
for i in range(N, 88889):
    tmp_set = set(map(int, list(str(i))))
    if tmp_set <= allow:
        print(i)
        break

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

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

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

D = [i for i in input().split()]
c = n

def match(A,B):
    for a in A:
        if a in B:
            return True
    else:
        return False
        
while True:
    if match(D,list(str(c))):
        c += 1
        continue
    else:
        break
    
    
print(c)

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

while True:
    if set(str(n)).intersection(o):
        n += 1
    else:
        break
print(n)

Solution (Python):
N,M=map(int,input().split())
s=list(input().split())
q=1
while q==1:
    for i in list(str(N)):
        if i in s:
            N=N+1
            break
    else:
        print(N)
        q=0

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

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

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

print(n)

Solution (Python):
N, K = map(int,input().split())
D = list(map(int,input().split()))
ans = N
while True:
    str_a = str(ans)
    OK = True
    for s in str_a:
        if int(s) in D:
            OK = False
            break
    if OK:
        break
    ans += 1
print(ans)

Solution (Python):
N,K=input().split()
nums = input().split()
cand = list(map(str,list(x for x in range(10))))
for num in nums:
  if num in cand:
    cand.remove(num)
work = []
if int(N) <= int(cand[-1]*len(N)):
  for i in range(len(N)):
    for c in cand:
      if int(N[i]) == int(c):
        work.append(c)
        break
      elif int(N[i]) < int(c):
        work.append(c)
        for j in range(i+1,len(N)):
          work.append(cand[0])
        print(''.join(work))
        exit()
else:
  if cand[0] != '0':
    work.append(cand[0])
  else:
    work.append(cand[1])
  for i in range(len(N)):
    work.append(cand[0])
print(''.join(work))

Solution (Python):
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)


def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                elif 0 in [k,l,m] and k != 0:
                                    continue
                                elif 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

Solution (Python):
n, k = list(map(int, input().split()))
d = list(map(int, input().split()))
if 0 in d:
    zero = True
else:
    zero = False

n_ok = {0} | set([0,1,2,3,4,5,6,7,8,9]) - set(d)
n_oks = sorted(n_ok)


def lowest():
    for i in n_oks:
        for j in n_oks:
            for k in n_oks:
                for l in n_oks:
                    for m in n_oks:
                        money = 10000*i +1000*j + 100*k + 10*l + m
                        if money >= n:
                            if zero:
                                if 0 in [i,j,k,l,m] and i != 0:
                                    continue
                                elif 0 in [j,k,l,m] and j != 0:
                                    continue
                                if 0 in [k,l,m] and k != 0:
                                    continue
                                if 0 in [l,m] and l != 0:
                                    continue
                            print(money)
                            return

lowest()

Solution (Python):
N,K=map(int,input().split())
D=[int(i) for i in input().split()]
T=[0 for i in range(10)]
for i in D:
    T[i]=1
S=[]
for i in range(10):
    if T[i]==0:
        S.append(i)
import itertools
L=[]
R=[]
if N>=1000:
    L=list(itertools.product(S,S,S,S))
    R=sorted([int(str(i[0])+str(i[1])+str(i[2])+str(i[3])) for i in L])
elif N>=100:
    L=list(itertools.product(S,S,S))
    R=sorted([int(str(i[0])+str(i[1])+str(i[2])) for i in L])
elif N>=10:
    L=list(itertools.product(S,S))
    R=sorted([int(str(i[0])+str(i[1])) for i in L])
else:
    L=list(itertools.product(S))
    R=sorted([int(str(i[0])) for i in L])
P=len(str(N))
for i in R:
    if int(i)>=N:
        print(i)
        exit()
if S[0]!=0:
    print(str(S[0])*(P+1))
else:
    print(str(S[1])+"0"*P)

Solution (Python):


INPUT = input()
N = int(INPUT.split()[0])


D_list = map(int, input().split())

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

usable_digits = DIGITS - set(D_list)

while True:
    N_set = set([int(x) for x in list(str(N))])
    if N_set <= usable_digits:
        break
    N += 1

print(N)

Solution (Python):
l = list(map(int,input().split()))
n = l[0]
k = l[1]
d = list(map(int,input().split()))

n_str = list(str(n))
can_use = []
for i in range(10):
    can_use.append(i)
    
for j in d:
    can_use.remove(j)


for i in range(len(n_str)):
    j = int(n_str[i])
    n_str[i] = j
    

ss = []

for i in range(n * 10 + 1):
    ss.append(n + i)

aaa = 0

for j in ss:
    jl = list(str(j))
    for k in range(len(jl)):
        m = int(jl[k])
        jl[k] = m
    if set(jl) <= set(can_use):
        aaa = jl
        break

bbb = ''
for i in aaa:
    bbb = bbb + str(i)
    
print(int(bbb))

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

while True:
  total = 0
  for num in nums:
    total += list(str(n)).count(str(num))
  
  if total == len(list(str(n))):
    print(n)
    break
  
  n += 1

Solution (Python):

input_array = list(map(int,input().split()))
N = input_array[0]
input_array = list(map(int,input().split()))

num = [1,1,1,1,1,1,1,1,1,1]
ok = []
out = []

for l in range(len(input_array)):
    num[input_array[l]] = 0

for i in range(len(num)):
    if num[i] == 0:
        ok.append(i)

while True:
    key = 0
    for n in list(str(N)):
        if int (n) in ok:
            key += 1
    if key == 0:
        print(N)
        break
    else:
        N+=1

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

Solution (Python):
n,k = (int(i) for i in input().split())
d = [int(i) for i in input().split()]
for i in range(n,88889):
	a = str(i)
	if all(int(j) not in d for j in a):
		print(i)
		break

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

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


minvalue=N
temp=0

for i in range(10*N):
    i=i+N
    numtemp=i
    if numtemp>=10000:
        num_4=int(i/10000)
        i=i-10000*num_4
    else:
        num_4=10
        
    if numtemp>=1000:
        num_3=int(i/1000)
        i=i-1000*num_3
    else:
        num_3=10
        
    if numtemp>=100:
        num_2=int(i/100)
        i=i-100*num_2
    else:
        num_2=10
        
    if numtemp>=10:
        num_1=int(i/10)
        i=i-10*num_1
    else:
        num_1=10
        
    num_0=i
    
    for j in range(K):
        if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
            temp+=1
            
    if temp==K:
        num=numtemp
        break
    
    temp=0

print(num)

Solution (Python):
from functools import reduce

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

R = N
while True:
    if reduce(lambda x, y: x and y, [s not in D for s in list(str(R))]):
        break
    R += 1
print(R)

Solution (Python):
a,b=map(int,(input().split()))
c=set(input())
while sum(i in c for i in str(a))>0:
	a+=1
print(a)

Solution (Python):
from functools import reduce

def obsession(n, disliked):
    def nearest(digit):
        for i in range(digit, digit + 10):
            mod10 = i % 10
            if mod10 not in disliked:
                return (mod10, i != mod10)

    will_pay = list(map(int, str(n)))
    index = 0
    while index < len(will_pay):
        digit = will_pay[index]
        if digit in disliked:
            substitute, carry = nearest(digit)
            will_pay[index] = substitute

            
            i = index + 1
            substitute, _ = nearest(0)
            while i < len(will_pay):
                will_pay[i] = substitute
                i += 1

            
            i = index - 1
            while carry and i >= 0:
                substitute, carry = nearest(will_pay[i] + 1)
                will_pay[i] = substitute
                i -= 1
            if carry:
                will_pay.insert(0, nearest(1)[0])
                index += 1
        index += 1
    return reduce(lambda x, y: x * 10 + y, will_pay, 0)


if __name__ == '__main__':
    n, _ = map(int, input().split())
    disliked = set(map(int, input().split()))
    print(obsession(n, disliked))

Solution (Python):
import sys

debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False
if debug_mode:
    import os
    inf = open(os.path.basename(__file__).replace(".py", ".in"))

    def input():
        return inf.readline()
else:
    inf = sys.stdin



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

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


main()



if debug_mode:
    inf.close()

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

def check(a):
  a=str(a)
  for i in range(len(a)):
    if int(a[i]) in A:
      return False
  return True

while not check(N):
  N+=1
print(N)

Solution (Python):
n,k=map(int,input().split())
d=set(map(str,input().split()))
for i in range(n,10*n):
    a=list(str(i))
    a=set(a)
    if a&d==set():
        print(i)
        break

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

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

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a
AC
"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens = set(forbiddens)
    ans = N
    repeat = True
    
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
                
    return ans


def main(args):
    
    
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc042/tasks/arc058_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(forbiddens, N):
    forbiddens.sort()

    ans = N
    repeat = True
    while repeat:
        repeat = False
        num_s = str(ans)
        for s in num_s:
            if int(s) in forbiddens:
                repeat = True
                ans += 1
                break
    return ans


def main(args):
    
    
    N, K = map(int, input().split())
    forbiddens = [int(x) for x in input().split()]
    ans = solve(forbiddens, N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
price, num = map(int,input().split())
dislike = list(input().split())
ans = price
p = 0
for i in range(10*price+1):
    s = str(ans)
    for j in range(len(str(s))):
        if s[j] in dislike:
            break
    else:
        break
    ans += 1
print(ans)

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

    while 1:
        f = 0
        hoge = str(n)
        for i in range(len(hoge)):
            for j in range(k):
                if(int(hoge[i]) == D[j]):
                    f = 1
                    break
                if f == 1:
                    break
            if f == 1:
                break
        if f == 0:
            print(n)
            break
        n += 1

if __name__ == "__main__":
    main()

Solution (Python):
def c_IrohaObsession(N, K, D):
    d = [str(i) for i in D]
    i = N
    while True:
        for c in str(i):
            if c in d:
                break
        else:
            return i
        i += 1
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D))

Solution (Python):
(n, k), d = map(int, raw_input().split()), set(raw_input().split())
for _ in xrange(n, 100001):
    if not set(str(_)) & d:
        print _
        break

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

for i in range(N, 100000):
    a = list(str(i))
    a = set(a)
    if a & D == set():
        print(i)
        break

Solution (Python):
def solve(d,s):
    for i in range(len(d)):
        if d[i] in s:
            return 1
    return 0

N,K = map(int,input().split())
D = list(map(str,input().split()))
m = N
while  solve(D,str(m)):
    m += 1
print(m)

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

Solution (Python):
N,K=map(int,raw_input().split())
D=map(int,raw_input().split())
n=[0,1,2,3,4,5,6,7,8,9]

a=[]	
for i in n:
	if i not in D:
		a.append(i)


i=N
while True:
	for j in D:
		if str(i).find(str(j))!=-1:
			break
	else:
		print str(i)
		break
	i+=1

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

for i in range(N, 100001):
    set_n = set(list(str(i)))
    for s in set_n:
        if s in D:
            break
    else:
        print(i)
        break

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

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


def valid(n):
    while n > 0:
        digit = n % 10
        if digit in d:
            return False
        n = int(n / 10)
    return True


for num in range(n, 10 * n):
    if valid(num):
        print(num)
        break

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

def digits(n):
  res = set()
  while n > 0:
    res = res.union(set([n%10]))
    n //= 10
  return res

for price in range(N, 10000000000000000):
  if digits(price).isdisjoint(D):
    print(price)
    break

Solution (Python):



"""042-c"""

import sys


def solve(dislike_digits_table, first_like_digit, N):
    """Solve."""
    for i, _ in enumerate(N):
        c = N[i]
        while dislike_digits_table[int(c)]:
            if c == '9':
                if i == 0:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 '1' + '0' * len(N))
                else:
                    return solve(dislike_digits_table,
                                 first_like_digit,
                                 str(int(N[0:i+1]) + 1)
                                    + '0' * len(N[i+1:]))
            else:
                c = chr(ord(c) + 1)
            N = N[0:i] + c + '0' * len(N[i+1:])

    return N


def main():
    """Main function."""
    dislike_digits_table = [False for _ in range(10)]

    N, _ = sys.stdin.readline().split(' ')
    digits = map(int, sys.stdin.readline().split(' '))

    for digit in digits:
        dislike_digits_table[digit] = True

    first_like_digit = str(next(i for i, v
                                in enumerate(dislike_digits_table)
                                if not v))

    print(solve(dislike_digits_table, first_like_digit, N))


if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
import math
a,b=(int(i) for i in input().split()) 
s=[int(i) for i in input().split()] 
n=[0,1,2,3,4,5,6,7,8,9]
n1 = [val for val in n if val not in s]
n1.sort()
keta=int(math.log10(a) + 1)
n_number=10-b
aa=str(a)
answer=[]
OKANE1=0
OKANE2=0
OKANE3=0
OKANE4=0
OKANE5=0

for i in range(n_number+1):
  for j in range(n_number+1):
    for k in range(n_number+1):
      for l in range(n_number+1):
        for m in range(n_number):
          if i!=0: 
            OKANE1=n1[i-1]
          if j!=0:          
            OKANE2=n1[j-1]
          if k!=0:           
            OKANE3=n1[k-1]
          if l!=0:           
            OKANE4=n1[l-1]
            
          OKANE5=n1[m]
          OKANE=10000*OKANE1+1000*OKANE2+100*OKANE3+10*OKANE4+OKANE5  
          if a<=OKANE:
            answer.append(OKANE)
print(min(answer))

Solution (Python):
import sys
N,K = list(map(int,input().split()))
D = input().split()
while True:
    breaked = False
    for i in range(len(str(N))):
        if str(N)[i] in D:
            breaked = True
            break
    if not(breaked):
        print(N)
        sys.exit()
    N += 1

Solution (Python):
n, k = map(int, raw_input().strip().split())
l = map(int, raw_input().strip().split())
ls = []
for x in l:
	ls.append(str(x))

def has_string(ns):
	r = True
	for x in ls:
		if x not in ns:
			pass
		else:
			r = False
	return r

while n < 100000:
	ns = str(n)
	if has_string(ns):
		print(ns)
		exit()
	else:
		n+=1

Solution (Python):
N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
  A.append(i)
for i in L:
  for j in L:
    A.append(10*i+j)
for  i in L:
  for j in L:
    for k in L:
      A.append(100*i+10*j+k)
for i in L:
  for j in L:
    for k in L:
      for l in L:
        A.append(1000*i+100*j+10*k+l)

for i in L:
  for j in L:
    for k in L:
      for l in L:
        for m in L:
          A.append(\
10000*i+1000*j+100*k+10*l+m)

for i in A:
  if i >= N:
    print(i)
    break

Solution (Python):
from itertools import count


def main():
    N, K = map(int, input().split())
    D_list = list(input().split())

    for c in count(N):
        c = str(c)
        for d in D_list:
            if d in c:
                break
        else:
            print(c)
            return


if __name__ == '__main__':
    main()

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

ans = N
while(1):
    j = True
    for d in D:
        if d in str(ans):
            j = False
            break
            
    if j == True:
        break
    ans += 1
print(ans)

Solution (Python):
nums = [int(x) for x in input().split()]
N,K = nums[0],nums[1]
D = set([int(x) for x in input().split()])

ans = N

def solve(M):
    M = [int(x) for x in str(M)]
    for m in M:
        if m in D: return False
    return True


while(1):
    if solve(ans):
        print(ans)
        break
    else:
        ans +=1

Solution (Python):
N, K = map(int, input().split())
D = list(map(str,input().split()))
ans = N
while sum([d in str(ans) for d in D]):
	ans+=1
print(ans)

Solution (Python):
a, _ = map(int, raw_input().split())
b = "".join(raw_input().split())
b = set(b)

for i in xrange(a, 99999999):
  if b.isdisjoint(str(i)):
    print i
    break

Solution (Python):
N,K = map(int, raw_input().split())
dislike = raw_input().split()
like = [str(n) for n in range(10) if str(n) not in dislike]

for n in range (N,100000):
  for d in str(n):
    if d in dislike: break
  else:
    print n
    break

Solution (Python):
N, K = map(int, raw_input().split())
D = map(int, raw_input().split())
W = filter(lambda x: not x in D, range(10))
def dfs(x):
    if x >= N:
        return x
    return min([dfs(10*x + d) for d in W])
print min([dfs(i) for i in W if (i > 0)])

Solution (Python):
def isValid(n,l):
    s = str(n)
    for c in s:
        if c in l:
            return False
    return True

n,k = map(int, raw_input().split())
dls = raw_input().split()
for i in range(n,100000):
    if isValid(i,dls):
        print i
        break

Solution (Python):

n,k = map(int,raw_input().split())
d = map(int,raw_input().split())
flg = 1
num = n-1
while(flg):
    num += 1
    strnum = str(num)
    check = [strnum.find(str(i))+1 for i in d]
    flg = sum(check)
print(num)

Solution (Python):
N,K = map(int,input().split())
D = list(map(int,input().split()))
for i in range(N*10):
    n = str(N + i)
    ok = True
    for j in D:
        if n.find(str(j)) != -1:
            ok = False
            break
    if ok:
        print(n)
        break