#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) int main() { int n,m; int where[1001] = {}; int migi[1001] = {},hida[1001] = {},s = 0; for(int i = 1;i < 1001;i++){ migi[i] = INF / 2; hida[i] = INF / 2; } cin >> n >> m; for(int i = 0;i < m;i++){ cin >> where[i]; } sort(where,where + m); int now = 1,how = 0; for(int i = 0;i < m;i++){ if(where[i] < 0) how++; if(where[i] == 0) s++; } for(int i = 0;i < m;i++){ if(where[i] > 0){ migi[now] = where[i]; now++; }else{ hida[how] = abs(where[i]); how--; } } int ans = INF; for(int i = 0;i <= n;i++){ ans = min(ans,min(2*migi[i] + hida[n - s - i],2*hida[i] + migi[n - s - i])); } cout << ans << endl; return 0; }