#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n, x, s;
  cin >> n >> x;
  for (int i = 0; i < x; i++) {
    cin >> a[i];
  }
  sort(a, a + x);
  int min = 100000;
  for (int i = 0; i < x - n + 1; i++) {
    if (a[i + n - 1] - a[i] < min) min = a[i + n - 1] - a[i];
  }
  cout << min << endl;
  return 0;
}
