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