#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (auto i = 0; i < m; i++) cin >> v[i];
  sort((v).begin(), (v).end());
  int x = m - n;
  int c = 1000000;
  for (int i = 0; i <= x; i++) {
    c = min(c, (v[i + n - 1] - v[i]));
  }
  cout << c << '\n';
  return 0;
}
