#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x = 0, y = 0, s = 0;
  cin >> n >> m;
  y = n - 1;
  vector<int> f, z;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    f.push_back(x);
  }
  make_heap(f.begin(), f.end());
  sort_heap(f.begin(), f.end());
  while (y < m) {
    s = f[y] - f[x];
    z.push_back(s);
    y += 1;
    x += 1;
  }
  make_heap(z.begin(), z.end());
  sort_heap(z.begin(), z.end());
  cout << z[0];
}
