x = raw_input()

x = x.split()

n,m = int(x[0]),int(x[1])


x = raw_input()
x = x.split()

a = [int(w) for w in x]

d = {}

for i in range(n):
    if a[i] in d:
        d[a[i]]+=1
    else:
        d[a[i]]=1


d[0] = 0
x = d.keys()

for i in range(1,len(x)):
    d[x[i]]+=d[x[i-1]]


#print d
if len(d)==2:
    print 0
else:    
    mini = 99999999
    for i in range(1,len(x)):
        for j in range(2,len(x)):
            if x[j] - x[i] > m:
                mini = min(mini,n-d[x[j-1]] + d[x[i-1]])
                break
            #elif d[x[j]] - d[x[i]] == m:
            #    mini = min(mini,n-d[x[j]])

    print mini
