import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class A {

  void solve() throws IOException {
    int n = nextInt();
    int d = nextInt();

    int[] a= new int[n];
    for(int i =0;i<n;i++)a[i]=nextInt();
    Arrays.sort(a);
    int ans = n;
    for(int i =0;i<n;i++) {
      int k=n-1;
      for(int j =i;j<n;j++) {
        if(a[j]-a[i]>d) {
          k=j-1;
          break;
        }
      }
      ans = Math.min(ans, n - (k-i+1));
    }
    out.println(ans);
  }

  public static void main(String[] args) throws IOException {
    new A().run();
  }

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  String nextToken() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }
}
