#include using namespace std; int main() { int n, m; cin >> n >> m; vector a, b; for (int i = 0; i < m; i++) { int d; cin >> d; if (d == 0) n--; else if (d > 0) a.push_back(d); else b.push_back(d); } sort(a.begin(), a.end()); sort(b.rbegin(), b.rend()); int ans = 1e9; for (int i = 0; i <= n; i++) { int j = n - i; int cand = 0; int x = 0; int num = 0; for (int k = 0; k < min(i, a.size()); k++) { num++; cand += abs(a[k] - x); x = a[k]; } for (int k = 0; k < min(j, b.size()); k++) { num++; cand += abs(b[k] - x); x = b[k]; } if (num == n) ans = min(ans, cand); } for (int i = 0; i <= n; i++) { int j = n - i; int cand = 0; int x = 0; int num = 0; for (int k = 0; k < min(j, b.size()); k++) { num++; cand += abs(b[k] - x); x = b[k]; } for (int k = 0; k < min(i, a.size()); k++) { num++; cand += abs(a[k] - x); x = a[k]; } if (num == n) ans = min(ans, cand); } cout << ans << endl; }