#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long MOD = (long long)(1e9 + 7);
const long long INIT = (long long)(1e6 + 1);
int32_t main() {
  long long n, m;
  cin >> m >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long dif = 1001;
  for (long long i = 0, j = m - 1; i <= n - m && j <= n - 1; i++, j++) {
    if ((a[j] - a[i]) < dif) {
      dif = a[j] - a[i];
    }
  }
  cout << dif;
  return 0;
}
