#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p, c, d;
  cin >> n >> m;
  int* arr = new int[m];
  for (int i = 0; i < m; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + m);
  p = arr[n - 1] - arr[0];
  c = n - 1;
  for (int i = 0; i < m && c < m; i++) {
    d = arr[c] - arr[i];
    if (d < p) {
      p = d;
    }
    c++;
  }
  cout << p << endl;
  return 0;
}
