#include <bits/stdc++.h>
using namespace std;
int main() {
  int qtd, loja;
  cin >> qtd >> loja;
  int entry;
  vector<int> pecas;
  map<int, int> mapa;
  for (int i = 0; i < loja; i++) {
    cin >> entry;
    pecas.push_back(entry);
    mapa[entry] = 0;
  }
  sort(pecas.begin(), pecas.end());
  int differ = 0, menor = 1000;
  for (int i = 0; i < loja - (qtd - 1); i++) {
    differ = pecas[i + qtd - 1] - pecas[i];
    if (differ < menor) menor = differ;
  }
  cout << menor << endl;
  return 0;
}
