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