#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> m >> n;
  vector<long long> v;
  long long x;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  long long dp = INT_MAX;
  for (long long i = 0; i <= n - m; i++) {
    dp = min(dp, v[i + m - 1] - v[i]);
  }
  cout << dp << "\n";
}
