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