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