#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> f(m);
  for (int i = 0; i < m; ++i) {
    cin >> f[i];
  }
  sort(f.begin(), f.end());
  int ans = INT_MAX;
  for (int i = 0; i < m - n + 1; ++i) {
    int range = f[n + i - 1] - f[i];
    ans = min(ans, range);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  ;
  return 0;
}
