// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll mod_pow(ll n, ll k) {
    ll res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

int main() {
    int N, K; cin >> N >> K;

    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.begin(), A.end(), [](ll a, ll b) {
            return abs(a) > abs(b);
        });

    ll mul = 1, plus = 0, minus = 0;
    for(int i=0; i<K; i++) {
        if(A[i] < 0) minus++;
        if(A[i] > 0) plus++;
        if(A[i] == 0) {
            puts("0");
            return 0;
        }
        mul *= abs(A[i]);
        mul %= MOD;
        if(A[i] < 0) mul = MOD - mul;
        mul %= MOD;
    }

    if(minus % 2 == 0 or N == K) {
        printf("%lld\n", mul);
        return 0;
    }

    int nega = 0;
    for(auto e : A) if(e < 0) nega++;
    if(nega == N) {
        sort(A.rbegin(), A.rend());
        mul = 1;
        for(int i=0; i<K; i++) {
            mul *= A[i];
            mul %= MOD;
            if(mul < 0) mul += MOD;
        }
        printf("%lld\n", mul);
        return 0;
    }

    // plus の中で最も小さいものを、K 個範囲外の minus と交換
    // minus の中で最も小さいものを、K 個範囲外の plus と交換
    ll ans = mul;
    ll a1 = -1, b1 = -1;
    if(plus > 0) {
        ll min_v = LONGINF;
        for(int i=0; i<K; i++) {
            if(A[i] <= 0) continue;
            chmin(min_v, abs(A[i]));
        }
        a1 = min_v;
        
        ll max_v = -LONGINF;
        for(int i=K; i<N; i++) {
            if(A[i] > 0) continue;
            chmax(max_v, abs(A[i]));
        }
        b1 = max_v;
    }
    ll a2 = -1, b2 = -1;
    if(minus > 0) {        
        ll min_v = LONGINF;
        for(int i=0; i<K; i++) {
            if(A[i] >= 0) continue;
            chmin(min_v, abs(A[i]));
        }
        a2 = min_v;
        
        ll max_v = -LONGINF;
        for(int i=K; i<N; i++) {
            if(A[i] < 0) continue;
            chmax(max_v, abs(A[i]));
        }
        b2 = max_v;
    }

    if(a1 >= 0 and a2 >= 0 and b1 >= 0 and b2 >= 0) {
        ans = MOD - ans;
        ans %= MOD;
        
        // a1, b1
        if(b1*a2 > b2*a1) {
            ans *= mod_pow(a1, MOD-2);
            ans %= MOD;
            ans *= b1;
            ans %= MOD;
        }
        // a2, b2
        else {
            ans *= mod_pow(a2, MOD-2);
            ans %= MOD;
            ans *= b2;
            ans %= MOD;
        }
    }
    else if(a1 >= 0 and b1 >= 0) {
        ans = MOD - ans;
        ans %= MOD;

        ans *= mod_pow(a1, MOD-2);
        ans %= MOD;
        ans *= b1;
        ans %= MOD;        
    }
    else if(a2 >= 0 and b2 >= 0) {
        ans = MOD - ans;
        ans %= MOD;
        
        ans *= mod_pow(a2, MOD-2);
        ans %= MOD;
        ans *= b2;
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4756