#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, v = 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 - n + 1; i++)
    if (v > a[i + n - 1] - a[i]) v = a[i + n - 1] - a[i];
  cout << v;
  return 0;
}
