ans = []
n,x=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
for i in range(n):
    for j in range(i,n):
        if max(arr[i:j+1])-min(arr[i:j+1])==x:
            ans.append(len(arr[i:j+1]))
if len(ans)==0:
    print(-1)
else:
    print (n-max(ans))
