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