#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int arr[50];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d", &arr[i]);
  sort(arr, arr + m);
  int max = 2000;
  for (int i = 0; i <= (m - n); i++) {
    if ((arr[i + n - 1] - arr[i]) < max) max = arr[i + n - 1] - arr[i];
  }
  printf("%d", max);
  return 0;
}
