#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int main() { int N, M; cin >> N >> M; vector D(M); rep(i, M) cin >> D[i]; sort(all(D)); ll ans = 1e10; /* int zr = upper_bound(all(D), 0) - D.begin(); zr --; if(zr >= N-1) { minimize(ans, abs(D[zr]) + abs(D[zr] - D[zr - N + 1])); } if(D[zr] < 0) zr ++; if(zr + N - 1 < M) { minimize(ans, abs(D[zr]) + abs(D[zr] - D[zr + N - 1])); } */ rep(i, M) REP(j, i, M) { if(D[i] >= 0 && j - i + 1 == N) { minimize(ans, D[j]); } if(D[j] <= 0 && j - i + 1 == N) { minimize(ans, abs(D[i])); } if(D[i] < 0 && D[j] > 0 && j - i + 1 == N) { minimize(ans, abs(D[i]) + abs(D[i] - D[j])); minimize(ans, abs(D[j]) + abs(D[i] - D[j])); } } cout << ans << endl; return 0; }