#include <bits/stdc++.h>
int main() {
  int tab[1000];
  int student, puzzle;
  int min, temp, count = 0;
  scanf("%d %d", &student, &puzzle);
  for (int i = 0; i < puzzle; i++) {
    scanf("%d", &tab[i]);
    count++;
    temp = tab[i];
    if (i > 0)
      for (int j = 0; j < count; j++) {
        if (tab[j] > tab[i]) {
          for (int k = i; k >= j; k--) {
            tab[k] = tab[k - 1];
          }
          tab[j] = temp;
        }
      }
  }
  for (int i = 0; i < puzzle - student + 1; i++) {
    if (i == 0)
      min = tab[student - 1] - tab[0];
    else if (tab[i + student - 1] - tab[i] < min)
      min = tab[i + student - 1] - tab[i];
  }
  printf("%d", min);
  return 0;
}
