#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  n--;
  vector<int> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  int min0 = v.at(n) - v.at(0);
  for (int i = 1; i < m - n; i++) {
    if (v.at(i + n) - v.at(i) < min0) min0 = v.at(i + n) - v.at(i);
  }
  cout << min0;
  return 0;
}
