#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (int i = 0; i < m; ++i) cin >> v[i];
  int MIN = 999999;
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < m - n + 1; i++) MIN = min(MIN, v[i] - v[i + n - 1]);
  cout << MIN << endl;
}
