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