#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b void vprint(T &V){ for(auto v : V){ cout << v << " "; } cout << endl; } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N, M; cin >> N >> M; vector A; // 正の方向 vector B; // 負の方向 FOR(i, 0, M){ ll x; cin >> x; if(x==0){ N -= x; if(N<=0){ p(0); return 0; } } if(x>0){ A.push_back(x); }else{ B.push_back(-x); // 正で入れる } } sort(ALL(A)); sort(ALL(B)); ll min_length = inf; // 片道で行ける場合 if(A.size()>=N){ chmin(min_length, A[N-1]); } if(B.size()>=N){ chmin(min_length, B[N-1]); } if(A.size()==0 || B.size()==0){ p(min_length); return 0; } // 折り返す // Aでi個取る場合 FOR(i, 1, A.size()){ ll path0 = A[i-1]; // Bでj個取る ll j = N-i; ll path1; if(j==0){ path1 = 0; }else{ path1 = B[j-1]; } ll length = min(2*path0 + path1, 2*path1 + path0); chmin(min_length, length); } p(min_length); return 0; }