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