#include "iostream"
#include "conio.h"
#include "math.h"
#include "stdlib.h"
#include "time.h"
#include "vector"
#include "algorithm" 
#include "numeric"
#include "string"
#include "ctime"
#define sp << " "
#define sps << " " <<
#define lnl << endl <<
#define ln << endl
typedef long long ll;
using namespace std;



int main()
{
	int n, d, mm = 10000;
	cin >> n >> d;
	vector<int>a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	if (n == 1)
	{
		cout << 0;
		return 0;
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n - 1; ++i)
		for (int j = i + 1; j < n; ++j)
			if (a[j] - a[i] <= d && i + n - 1 - j < mm)
				mm = i + n - 1 - j;
	cout << mm;
}
