#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i = 0;
  vector<int> v;
  for (i = 0; i < m; i++) {
    int num;
    scanf("%d", &num);
    v.push_back(num);
  }
  sort(v.begin(), v.end());
  int min = v[n - 1] - v[0];
  for (i = n; i < m; i++) {
    if (v[i] - v[i - n + 1] < min) min = v[i] - v[i - n + 1];
  }
  printf("%d", min);
  return 0;
}
