#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f[55], min = 1000;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> f[i];
  sort(f, f + m);
  for (int i = 0, j = n - 1; j < m; i++, j++) {
    if (f[j] - f[i] < min) {
      min = f[j] - f[i];
    }
  }
  cout << min << endl;
}
