#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, numPie[100], miin = INT_MAX;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> numPie[i];
  sort(numPie, numPie + m);
  for (int i = 0; i <= m - n; i++) {
    int A_B = numPie[i + (n - 1)] - numPie[i];
    if (A_B < miin) miin = A_B;
  }
  cout << miin;
  return 0;
}
