#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  unsigned short n{}, m{};
  cin >> n >> m;
  --n;
  vector<short> v(m);
  for (auto &x : v) cin >> x;
  sort(v.begin(), v.end());
  auto ans{SHRT_MAX};
  const auto l = m - n;
  for (auto i{0u}; i < l; i++) ans = min(ans, v[i + n] - v[i]);
  cout << ans;
  return 0;
}
