#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, l, m, n, c, t, x, y;
  string s;
  vector<long long> v;
  map<long long, long long> mp;
  scanf("%lld %lld", &m, &n);
  c = 0;
  long long a[n];
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a, a + n);
  j = 0;
  k = INT_MAX;
  while (1) {
    l = a[j + m - 1] - a[j];
    if (j + m <= n)
      k = min(k, l);
    else
      break;
    j++;
  }
  printf("%lld\n", k);
}
