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