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