/* */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pint; typedef vector vint; typedef vector vpint; #define mp make_pair #define fi first #define se second #define all(v) (v).begin(),(v).end() #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) int dx[4] = {1, 0, 0, -1}; int dy[4] = {0, 1, -1, 0}; int main(void){ int n, m; scanf("%d %d", &n, &m); int tmp_sei[m]; int tmp_fu[m]; int sei = 0, zero = 0, fu = 0, tmp; rep(i, m){ scanf("%d", &tmp); if (tmp > 0){ tmp_sei[sei] = tmp; sei++; }else if(tmp == 0){ zero++; }else{ tmp_fu[fu] = tmp; fu++; } } vector d_sei(sei); //vector d_zero(m); vector d_fu(fu); rep(i, sei) d_sei[i] = tmp_sei[i]; rep(i, fu) d_fu[i] = tmp_fu[i]; //大きくなるように sort(d_sei.begin(), d_sei.end()); //小さくなるように sort(d_fu.begin(), d_fu.end(), greater()); int ans = 10000000; int sum; //n個取ればいい /***********/ /*printf("fu%d\n", fu); printf("sei%d\n", sei); printf("zero%d\n", zero); printf("n%d\n", n);*/ if (fu >= n - zero){ //負だけから撮る時 sum = d_fu[n - zero - 1] * -1; //printf("%d\n", sum); ans = min(ans, sum); } if(sei >= n - zero){ //正だけから撮る時 sum = d_sei[n - zero - 1]; //printf("%d\n", ans); ans = min(ans, sum); } for (int i = 1; i <= n - zero - 1; ++i) //i個 { for (int j = n - zero -1; j <= 1; --j) //j個 { sum += (d_fu[i - 1] * -1 + d_sei[j - 1]); ans = min(ans, sum); } } printf("%d\n", ans); return 0; }