#include <bits/stdc++.h>
using namespace std;
typedef long double real;
int n, m;
vector<int> L;
int main() {
  scanf("%d %d", &n, &m);
  L.resize(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &L[i]);
  }
  sort((L).begin(), (L).end());
  int ans = INT_MAX;
  for (int l = 0; l < m; ++l) {
    for (int r = l + n - 1; r < m; ++r) {
      ans = min(ans, L[r] - L[l]);
    }
  }
  printf("%d\n", ans);
}
