
import java.util.*;
import java.io.*;


public class TestReader {


  public static void main(String[] args) {
    InputStream stream = System.in;
    PrintWriter out = new PrintWriter(System.out);
    FastReader sc = new FastReader(stream);
    //int t = sc.nextInt();
    Solver solver = new Solver();
    int t = 1;
    while(t-->0) {
      solver.solve(sc,out);
    }
    out.close();
  }
  
  static class Solver {
    public void solve(FastReader sc, PrintWriter out) {
      int n = sc.nextInt();
      int d = sc.nextInt();
      int[] arr = new int[n];
      for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
      Arrays.sort(arr);
      int best = 1;
      for(int len = n; len > 1; len--) {
        boolean found = false;
        for(int i = 0; i + len <= n; i++) {
          if(arr[i+len-1]-arr[i]<=d) {
            found = true;
            break;
          }
        }
        if(found) {
          best = len;
          break;
        }
      }
      out.println(n-best);
    }
  }
  
  static class FastReader {
    InputStream stream;
    byte[] buf = new byte[1024];
    int curChar, numChars;
    public FastReader(InputStream stream) {
      this.stream = stream;
    }
    
    public int read() {
      if(numChars==-1) {
        throw new InputMismatchException();
      }
      if(curChar>=numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch(IOException e) {
          throw new InputMismatchException();
        }
        if(numChars<=0) {
          return -1;
        }
      }
      return buf[curChar++];
    }
    
    public int nextInt() {
      int c = read();
      while(isWhiteSpace(c)) c = read();
      int sign = 1;
      if(c == '-') {
        sign = -1;
        c = read();
      }
      int res = 0;
      do {
        if(c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c-'0';
        c = read();
      } while(!isWhiteSpace(c));
      return res*sign;
    }
    
    public long nextLong() {
      int c = read();
      while(isWhiteSpace(c)) c = read();
      int sign = 1;
      if(c == '-') {
        sign = -1;
        c = read();
      }
      long res = 0;
      do {
        if(c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c-'0';
        c = read();
      } while(!isWhiteSpace(c));
      return res*sign;
    }
    
    public String next() {
      int c = read();
      while(isWhiteSpace(c)) c = read();
      StringBuilder res = new StringBuilder();
      do {
        if(Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();;
      } while(!isWhiteSpace(c));
      return res.toString();
    }
    
    public boolean isWhiteSpace(int c) {
      return c == ' ' || c == '\n' ||
             c == '\r' || c == '\t' ||
             c == -1;
    }
  }
}
