#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  2 09:58:19 2018

@author: mikolajbinkowski
"""

n, d = [int(k) for k in input().split(' ')]
points = [int(k) for k in input().split(' ')]
          
def qs(A, l, r):
    if l >= r:
        return
    p = part(A, l, r)
    qs(A, l, p - 1)
    qs(A, p + 1, r)
    
def part(A, l, r):
    if l == r:
        return l
    pivot = A[r]
    i = l
    for j in range(l, r):
        if A[j] < pivot:
            swap(A, j, i)
            i += 1
    swap(A, r, i)
    return i
    
def swap(A, i, j):
    c= A[i]
    A[i] = A[j]
    A[j] = c

qs(points, 0, n - 1)

i, j = 0, 0
max_dist = 0
while j < n:
    while points[j] - points[i] <= d:
        j += 1
        if j >= n:
            break
    dist = j - i
    if dist > max_dist:
        max_dist = dist
    i += 1
print(n - max_dist)
