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