#include <bits/stdc++.h>
using namespace std;
int arr[52];
int n, m;
int memo[52][52][52][52];
int dp(int pos, int mini, int maxi, int c) {
  if (c < 0) return 1e7;
  if (pos >= m) {
    if (!c) return arr[maxi] - arr[mini];
    return 1e7;
  }
  int &ret = memo[pos][mini][maxi][c];
  if (ret != -1) return ret;
  int A = dp(pos + 1, mini, maxi, c);
  int B = dp(pos + 1, arr[pos] < arr[mini] ? pos : mini,
             arr[pos] < arr[maxi] ? maxi : pos, c - 1);
  return ret = min(A, B);
}
int main() {
  cin >> n >> m;
  memset(memo, -1, sizeof memo);
  for (int i = 0; i < m; i++) cin >> arr[i];
  arr[50] = 1e8;
  arr[51] = -1e8;
  cout << dp(0, 50, 51, n) << endl;
}
