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