// Arup Guha
// 10/12/2013
// Solution to UCF JV Practice Problem B: Puzzles.

import java.util.*;

public class b {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int k = stdin.nextInt();
		int n = stdin.nextInt();

		// Read in the values.
		int[] vals = new int[n];
		for (int i=0; i<n; i++)
			vals[i] = stdin.nextInt();

		// Greedily sort since we want to buy a contiguous set of puzzles, sorted.
		Arrays.sort(vals);

		// This is buying the k cheapest.
		int best = vals[k-1] - vals[0];

		// Try all other k consecutive puzzles and update, if necessary.
		for (int i=1; i<=n-k; i++) {
			int temp = vals[k-1+i] - vals[i];
			if (temp < best)
				best = temp;
		}
		System.out.println(best);
	}
}