#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int mod = 1e9 + 7;
int32_t main() {

    simplify
    int n, k;
    cin >> n >> k;

    vector<int>positive, negative;
    int temp;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp > 0)positive.push_back(temp);
        else negative.push_back(temp);
    }
    sort(positive.rbegin(), positive.rend());
    sort(negative.begin(), negative.end());
    int ans = 1;
    int posSize = positive.size();
    int negSize = negative.size();
    int posAns, negAns;
    if(positive.size() == 0 && k % 2 == 1) {
        int si = negative.size();
        for(int i = si - 1; i >= (si - k); i--) {
            ans *= negative[i];
            ans += mod;
            ans %= mod;
        }
        if(ans < 0)ans += mod;
        //cout << ans << endl;
    } else if(k % 2 == 1) {
        ans = positive[0];
        k--;
        k /= 2;
        int posCurr, negCurr;
        posCurr = 1;
        negCurr = 0;

        while(k--) {
            posAns = negAns = INT_MIN;
            if(posCurr + 1 < posSize) {
                posAns = positive[posCurr] * positive[posCurr + 1];
            }
            if(negCurr + 1 < negSize) {
                negAns = negative[negCurr] * negative[negCurr + 1];
            }
            if(posAns < negAns && negCurr + 1 < negSize) {
                negAns %= mod;
                negCurr += 2;
                ans *= negAns;
                ans %= mod;

            } else if(posCurr + 1 < posSize) {
                posCurr += 2;
                posAns %= mod;
                ans *= posAns;
                ans %= mod;
            } else {
                posAns = positive[posCurr] * negative[negCurr];
                if(posAns < 0) {
                    posAns += mod * mod;
                    posAns %= mod;
                }
                ans *= posAns;
                ans %= mod;
            }
        }
    } else {
        ans = 1;
        k /= 2;
        int posCurr, negCurr;
        posCurr = 0;
        negCurr = 0;

        while(k--) {
            posAns = negAns = INT_MIN;
            if(posCurr + 1 < posSize) {
                posAns = positive[posCurr] * positive[posCurr + 1];
            }
            if(negCurr + 1 < negSize) {
                negAns = negative[negCurr] * negative[negCurr + 1];
            }
            if(posAns < negAns && negCurr + 1 < negSize) {
                negAns %= mod;
                negCurr += 2;
                ans *= negAns;
                ans %= mod;

            } else if(posCurr + 1 < posSize) {
                posCurr += 2;
                posAns %= mod;
                ans *= posAns;
                ans %= mod;
            } else {
                posAns = positive[posCurr] * negative[negCurr];
                if(posAns < 0) {
                    posAns += mod * mod;
                    posAns %= mod;
                }
                ans *= posAns;
                ans %= mod;
            }
            //cout << ans << " ** " << endl;
        }
    }

    cout << ans << endl;




    return 0;
}



Measured memory_bytes: 5664