#include <bits/stdc++.h>
using namespace std;
int a[1200], b[1200];
int m, n;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  sort(a, a + m);
  for (int i = 0; i <= m - n; i++) {
    b[i] = a[i + n - 1] - a[i];
  }
  int min = b[0];
  for (int i = 0; i <= m - n; i++) {
    if (min > b[i]) min = b[i];
  }
  cout << min;
  return 0;
}
