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