#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, ans = 1000;
  cin >> n >> m;
  vector<int> v(m);
  for (i = 0; i < m; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (i = 0; i <= m - n; i++)
    if (v[i + n - 1] - v[i] < ans) ans = v[i + n - 1] - v[i];
  cout << ans << endl;
  return 0;
}
