#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, temp;
  cin >> n >> m;
  int ar[m];
  for (int i = 0; i < m; i++) cin >> ar[i];
  for (int i = 0; i < m - 1; i++) {
    for (int j = 0; j < m - i - 1; j++)
      if (ar[j] > ar[j + 1]) {
        temp = ar[j + 1];
        ar[j + 1] = ar[j];
        ar[j] = temp;
      }
  }
  temp = 1001;
  for (int i = 0; i <= m - n; i++) {
    if (ar[n + i - 1] - ar[i] < temp) temp = ar[n + i - 1] - ar[i];
  }
  cout << temp;
  return 0;
}
