#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, res;
  cin >> n >> m;
  int f[m];
  for (i = 0; i < m; i++) {
    cin >> f[i];
  }
  sort(f, f + m);
  res = f[n - 1] - f[0];
  for (i = n; i < m; i++) {
    res = min(res, f[i] - f[i - n + 1]);
  }
  cout << res;
  return 0;
}
