#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
int BigMod(long long int B, long long int P, long long int M) {
  long long int R = 1;
  while (P > 0) {
    if (P % 2 == 1) R = (R * B) % M;
    P /= 2;
    B = (B * B) % M;
  }
  return (int)R;
}
long long int maxDivide(long long int a, long long int b) {
  while (a % b == 0) a = a / b;
  return a;
}
long long int isUgly(long long int no) {
  no = maxDivide(no, 2);
  no = maxDivide(no, 3);
  no = maxDivide(no, 5);
  return (no == 1) ? 1 : 0;
}
long long int myXOR(long long int x, long long int y) {
  long long int res = 0;
  for (long long int i = 31; i >= 0; i--) {
    bool b1 = x & (1 << i);
    bool b2 = y & (1 << i);
    bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);
    res <<= 1;
    res |= xoredBit;
  }
  return res;
}
long long int ar[55];
int main() {
  long long int n, m, a, b, c, d, x, y, mn, mx;
  scanf("%lld%lld", &n, &m);
  for (long long int i = 0; i <= m - 1; i++) {
    scanf("%lld", &ar[i]);
  }
  sort(ar, ar + m);
  x = INF;
  for (long long int i = 0; i <= m - n; i++) {
    mx = -INF;
    mn = INF;
    for (long long int j = i; j <= i + n - 1; j++) {
      if (ar[j] > mx) mx = ar[j];
      if (ar[j] < mn) mn = ar[j];
    }
    if (mx - mn < x) {
      x = mx - mn;
      a = i;
    }
  }
  printf("%lld\n", x);
  return 0;
}
