#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second

#define pow10(n) stoll("1"+string(n,'0'))

#define debug(x) cout << ">>> " << #x << ": " << x << '\n'

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LNF = 1e18;

void setIO(string s) {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {

    setIO("input");
    int n, k; cin >> n >> k;
    bool pos = false;
    vl a(n);
    deque<ll> P, N;
    for(auto& i : a) {
        cin >> i;
        if(i > 0) {
            pos = true;
        }
        if(i >= 0) P.eb(i);
        else N.eb(i);
    }
    ll ans = 1;
    // forced to take everything
    if(n == k) {
        for(auto& i : a)
            ans = (ans * i) % MOD;
        cout << (ans + MOD) % MOD;
        exit(0);
    }
    // can only take negatives, so take the smallest ones
    if(k & 1 && !pos) {
        sort(all(a), [](const ll& a, const ll& b) {
            return abs(a) < abs(b);
        });
        for(int i=0; i<k; ++i)
            ans = (ans * a[i]) % MOD;
        cout << (ans + MOD) % MOD;
        exit(0);
    }

    sort(rall(P));
    sort(all(N));

    if(k & 1) {
        --k;
        ans = P.front();
        P.pop_front();
    }

    while(k) {
        if(P.size() < 2) {
            ans = (ans * N.front()) % MOD;
            N.pop_front();
            ans = (ans * N.front()) % MOD;
            N.pop_front();
        }
        else if(N.size() < 2) {
            ans = (ans * P.front()) % MOD;
            P.pop_front();
            ans = (ans * P.front()) % MOD;
            P.pop_front();
        }
        else {
            ll pos1 = P[0], pos2 = P[1], neg1 = N[0], neg2 = N[1];
            if(pos1 * pos2 >= neg1 * neg2) {
                ans = (ans * pos1) % MOD;
                ans = (ans * pos2) % MOD;
                P.pop_front(), P.pop_front();
            }
            else {
                ans = (ans * neg1) % MOD;
                ans = (ans * neg2) % MOD;
                N.pop_front(), N.pop_front();
            }
        }
        k -= 2;
    }

    cout << ans;

}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

Measured memory_bytes: 6884