#include <stdio.h> #include <stdlib.h> #define MAXSIZE 60 int comp_inc(const void *first, const void *second); int main() { int pieces[MAXSIZE]; int n, m; scanf("%d%d", &n, &m); int i; for(i=0; i<m; ++i) scanf("%d", &pieces[i]); qsort(pieces, m, sizeof(pieces[0]), comp_inc); int min=1010; for(i=0; i<=(m-n); ++i) { if(pieces[i+n-1]-pieces[i]<min) min=pieces[i+n-1]-pieces[i]; } printf("%d\n", min); return 0; } int comp_inc(const void *first, const void *second) { return *(int *)first-*(int *)second; }