
import java.util.Arrays;
import java.util.Scanner;


public class pointsontheline {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d  = input.nextInt();
        int arr[]= new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=input.nextInt();
        }
        Arrays.sort(arr);
        if(n==1) System.out.println("0");
        else
        {
        int j = n-1;
        int i= 0;
        int count = 0;
      do{
          int num = arr[j]-arr[i];
      if(num>d) j--;
      else if(num<d)i++;
      
      }while((arr[j]-arr[i])!=d);
        System.out.println((n-1-j)+i);
    }
    }
}
