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