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