import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

public class Task940A {

    public static class FastScanner {

        protected DataInputStream dataInputStream;
        protected byte[] buffer = new byte[0x10000];
        protected int bufferOffset;
        protected int bufferLength;
        protected boolean isEndOfFile;

        public FastScanner() throws IOException {
            dataInputStream = new DataInputStream(System.in);
            Read();
        }

        public FastScanner(final String fileName) throws IOException {
            dataInputStream = new DataInputStream(new FileInputStream(fileName));
            Read();
        }

        protected void Read() throws IOException {
            final int length = dataInputStream.read(buffer);
            if (length > 0) {
                bufferLength = length;
            } else {
                bufferLength = 0;
                isEndOfFile = true;
            }
            bufferOffset = 0;
        }

        protected byte nextByte() throws IOException {
            if (bufferOffset == bufferLength) {
                if (!isEndOfFile) Read();
                if (isEndOfFile) return 0;
            }
            return buffer[bufferOffset++];
        }

        public int nextInt() throws IOException {
            int a = 0;
            boolean isNegative = false;

            byte b = nextByte();
            while (b <= ' ') b = nextByte();
            if (b == '-') {
                isNegative = true;
                b = nextByte();
            }
            while (b > ' ') {
                a = a * 10 + (b - '0');
                b = nextByte();
            }
            return isNegative ? -a : a;
        }

    }

    public static void main(final String[] args) throws IOException {
        final FastScanner scanner = new FastScanner();
        final int n = scanner.nextInt();
        final int d = scanner.nextInt();

        final int[] x = new int[n];

        for (int i = 0; i < n; i++) {
            x[i] = scanner.nextInt();
        }

        Arrays.sort(x);

        int off1 = 0;
        int off2 = 0;

        int minToRemove = n;

        while (off2 < n) {
            final int dcur = x[off2] - x[off1];
            if (dcur <= d) {
                final int toRemove = n - (off2 - off1) - 1;
                minToRemove = Math.min(toRemove, minToRemove);
                off2++;
            } else {
                off1++;
            }
        }
        System.out.println(minToRemove);
    }

}
