#include using namespace std; const int MAX_N = 1000; int D[MAX_N]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector L, R; L.emplace_back(0); R.emplace_back(0); for (int i = 0; i < m; i++) { cin >> D[i]; if (D[i] < 0) L.emplace_back(-D[i]); else R.emplace_back(D[i]); } sort(L.begin(), L.end()); sort(R.begin(), R.end()); int l = L.size(), r = R.size(); vector dp(l); int ans = 100000000; for (int i = max(n - r + 1, 0), e = min(l, n + 1); i < e; i++) { dp[i] = min(L[i] * 2 + R[n - i], L[i] + R[n - i] * 2); ans = min(ans, dp[i]); } cout << ans << "\n"; return 0; }