#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int arr[100000];
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr, arr+n);
int result = 2000000000;
int s = 0;
int e = 0;
while(s!=n && e!=n){
if(arr[e] - arr[s]>=m){
result = min(result, arr[e]-arr[s]);
s++;
}else{
e++;
}
}
cout<<result;
}