#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
  }
  int ans = 0x3f3f3f3f;
  sort(begin(a), end(a));
  for (int i = n - 1; i < m; ++i) {
    ans = min(ans, a[i] - a[i - (n - 1)]);
  }
  cout << ans << '\n';
  return 0;
}
