#include <bits/stdc++.h>
int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[100], min = 100000000, i;
  for (i = 0; i < m; i++) scanf("%d", &a[i]);
  qsort(a, m, sizeof(int), cmp);
  for (i = 0; i < m - n + 1; i++) {
    int temp = a[i + n - 1] - a[i];
    if (temp < min) min = temp;
  }
  printf("%d\n", min);
  return 0;
}
