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