// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<cmath>

using namespace std;

const int BUF = 200005;

const int MOD = 1000000007;

const int INF = 1<<30;





int nVal, nPick;

int val[BUF];



void read() {

    cin >> nVal >> nPick;

    for (int i = 0; i < nVal; ++i) {

        cin >> val[i];

    }

}





void work() {

    int nNeg = 0, nZero = 0, nPos = 0;

    int neg[BUF], pos[BUF];



    for (int i = 0; i < nVal; ++i) {

        if (val[i] < 0) {

            neg[nNeg++] = val[i];

        } else if (val[i] > 0) {

            pos[nPos++] = val[i];

        } else {

            ++nZero;

        }

    }



    sort(neg, neg + nNeg);

    sort(pos, pos + nPos);



    long double posLogSum[BUF];

    posLogSum[0] = logl(pos[0]);

    for (int i = 1; i < nPos; ++i) {

        posLogSum[i] = posLogSum[i - 1] + logl(pos[i]);

    }

    

    long double maxV = -INF;

    int nNegPickMax = -1;

    long double cur = 0;

    for (int nNegPick = 0; nNegPick <= min(nNeg, nPick); nNegPick += 2) {

        if (nNegPick) {

            cur += logl(fabs(neg[nNegPick - 1]));

            cur += logl(fabs(neg[nNegPick - 2]));

        }

        

        int nRemainPick = nPick - nNegPick;

        if (nRemainPick > nPos) {

            continue;

        }

        

        long double sum = (nPos == 0 ? 0 : posLogSum[nPos - 1]) - (nRemainPick == nPos ? 0 : posLogSum[nPos - 1 - nRemainPick]);

        if (maxV < cur + sum) {

            maxV = cur + sum;

            nNegPickMax = nNegPick;

        }

    }

    

    if (nNegPickMax != -1) {

        int ans = 1;

        for (int i = 0; i < nNegPickMax; ++i) {

            ans = 1LL * ans * (MOD + neg[i]) % MOD;

        }

        for (int i = 0; i < nPick - nNegPickMax; ++i) {

            ans = 1LL * ans * pos[nPos - 1 - i] % MOD;

        }

        cout << ans << endl;

        return;

    } else if (nZero) {

        cout << 0 << endl;

        return;

    }



    

    reverse(neg, neg + nNeg);



    long double minV = INF;

    

    cur = logl(fabs(neg[0]));

    for (int nNegPick = 1; nNegPick <= min(nNeg, nPick); nNegPick += 2) {

        if (nNegPick > 1) {

            cur += logl(fabs(neg[nNegPick - 1]));

            cur += logl(fabs(neg[nNegPick - 2]));

        }

        

        int nRemainPick = nPick - nNegPick;



        if (nRemainPick > nPos) {

            continue;

        }

        

        long double sum = nRemainPick == 0 ? 0 : posLogSum[nRemainPick - 1];

        if (minV > cur + sum) {

            minV = cur + sum;

            nNegPickMax = nNegPick;

        }

    }



    int ans = 1;

    for (int i = 0; i < nNegPickMax; ++i) {

        ans = 1LL * ans * (MOD + neg[i]) % MOD;

    }

    for (int i = 0; i < nPick - nNegPickMax; ++i) {

        ans = 1LL * ans * pos[i] % MOD;

    }

    cout << ans << endl;

}





int main() {

    read();

    work();

    return 0;

}


// Optimized solution to the same problem (faster):
#include<iostream>

#include<algorithm>

using namespace std;

const int BUF = 200005;

const int MOD = 1000000007;





int pow(int p, int n) {

    if (n == 0) return 1;

    int t = pow(p, n / 2);

    return n & 1 ? 1LL * t * t % MOD * p % MOD: 1LL * t * t % MOD;

}





int inv(int v) {

    return pow(v, MOD - 2);

}





int nVal, nPick;

int val[BUF];



void read() {

    cin >> nVal >> nPick;

    for (int i = 0; i < nVal; ++i) {

        cin >> val[i];

    }

}





bool cmp(int a, int b) {

    return abs(a) < abs(b);

}





void work() {

    sort(val, val + nVal, cmp);

    reverse(val, val + nVal);



    if (nPick == nVal) {

        int ans = 1;

        for (int i = 0; i < nVal; ++i) {

            ans = 1LL * ans * (MOD + val[i]) % MOD;

        }

        cout << ans << endl;

        return;

    }



    if (nPick % 2 == 1 && *max_element(val, val + nVal) <= 0) {

        int ans = 1;

        for (int i = nVal - 1; i >= nVal - nPick; --i) {

            ans = 1LL * ans * (MOD + val[i]) % MOD;

        }

        cout << ans << endl;

        return;

    }



    bool isNeg = false;

    int ans = 1;

    for (int i = 0; i < nPick; ++i) {

        ans = 1LL * ans * (MOD + val[i]) % MOD;

        if (val[i] < 0) isNeg = !isNeg;

    }



    if (!isNeg) {

        cout << ans << endl;

        return;

    }



    int posMinIdx = -1;

    int negMinIdx = -1;

    for (int i = nPick - 1; i >= 0; --i) {

        if (val[i] > 0 && posMinIdx == -1) {

            posMinIdx = i;

        }

        if (val[i] < 0 && negMinIdx == -1) {

            negMinIdx = i;

        }

    }



    int posMaxIdx = -1;

    int negMaxIdx = -1;

    for (int i = nPick; i < nVal; ++i) {

        if (val[i] > 0 && posMaxIdx == -1) {

            posMaxIdx = i;

        }

        if (val[i] < 0 && negMaxIdx == -1) {

            negMaxIdx = i;

        }

    }

    

    if (negMinIdx == -1 || posMaxIdx == -1 ||

        (posMinIdx != -1 && negMaxIdx != -1 && 1LL * abs(val[negMaxIdx]) * abs(val[negMinIdx]) > 1LL * val[posMinIdx] * val[posMaxIdx])) {

        // ans / posMin * negMax > ans / negMin * posMax

        ans = 1LL * ans * inv(val[posMinIdx]) % MOD;

        ans = 1LL * ans * (MOD + val[negMaxIdx]) % MOD;

    } else {

        ans = 1LL * ans * inv(MOD + val[negMinIdx]) % MOD;

        ans = 1LL * ans * val[posMaxIdx] % MOD;

    }



    cout << ans << endl;

}





int main() {

    read();

    work();

    return 0;

}


// Fastest known solution for this problem: