#include<bits/stdc++.h>
using namespace std;
using lint = long int;
#define pb push_back
#define MOD 1000000007

lint N, K, val;
lint res = 1;
lint plen, nlen, zlen = 0;
bool sign, usable = true;
vector<lint> pA;
vector<lint> nA;

bool is_plus(lint p, lint k){
    if(k & 1){
        if(p > 0) return true; //正の数が皆無
        else return false;
    }
    return true;  //偶数は確実
}


bool use_minus_val(lint& n, lint& kk, lint& r){
    if(n == (lint)nA.size()) return false;
    while(kk > 0){
        r *= abs(nA[n]); r %= MOD;
        r *= abs(nA[n+1]); r %= MOD;
        n += 2; kk-=2;
    }
    return true;
}


bool use_plus_val(lint& p, lint& kk, lint& r){
    if(p == (lint)pA.size()) return false;
    while(kk > 0){
        r *= pA[p]; r %= MOD;
        r *= pA[p+1]; r %= MOD;
        p += 2; kk-=2;
    }
    return true;
}


void use_norp_val(lint& n, lint& p, lint& kk, lint& r){
    lint pp = pA[p]*pA[p+1];
    lint nn = nA[n]*nA[n+1];
    if(pp > nn){
        r *= pA[p]; r %= MOD;
        r *= pA[p+1]; r %= MOD;
        p += 2; kk -= 2;
    }else{
        r *= abs(nA[n]); r %= MOD;
        r *= abs(nA[n+1]); r %= MOD;
        n += 2; kk -= 2;
    }
}


int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> val;
        if(val < 0) nA.pb(val);
        else if(val > 0) pA.pb(val);
        else ++zlen;
    }


    plen = pA.size(); nlen = nA.size();

    if(K > plen + nlen) res = 0;  //0を使わざるを得ない
    else if(K==N){  //K == N <= plen + nlenより,zlen = 0
        for(int i = 0; i < plen; i++){ res *= pA[i]; res %= MOD; }
        for(int i = 0; i < nlen/2; i++){
            res *= abs(nA[2*i]); res %= MOD;
            res *= abs(nA[2*i+1]); res %= MOD;
        }
        if(nlen & 1){
            res *= nA[nlen-1];
            res += (abs(res)/MOD+1) * MOD;
        }
    }else{

        lint k = K;
        lint pk = 0, nk = 0;

        if(is_plus(plen, K)){
            /*絶対値が大きい値を先頭に*/
            sort(nA.begin(), nA.end());
            sort(pA.begin(), pA.end());
            reverse(pA.begin(), pA.end());
            sign = true;
        }else{
            /*絶対値が小さい値を先頭に*/
            sort(nA.begin(), nA.end());
            reverse(nA.begin(), nA.end());
            sort(pA.begin(), pA.end());
            sign = false;
        }
      

        if(K & 1){  //Kが奇数
            if(sign){  //pAサイズ1以上,偶数なら2以上が保障
                res *= pA[pk++];
                --k;  //残り偶数個必要
                while(k > 0 && usable){  //kは偶数
                    if(plen-pk < 2) usable = use_minus_val(nk, k, res);
                    else if(nlen-nk < 2) usable = use_plus_val(pk, k, res);
                    else use_norp_val(nk, pk, k, res);
                }
            }else{    //負の値となる
                if(zlen > 0) res = 0;
                else {
                    while(k > 1){
                        res *= abs(nA[nk]); res %= MOD;
                        res *= abs(nA[nk+1]); res %= MOD;
                        nk += 2; k -= 2;
                    }
                    res *= nA[nk];
                    res += (abs(res)/MOD + 1) * MOD;
                }
            }

        }else{    //Kが偶数
            while(k > 0){
                if(plen-pk <= 1) usable = use_minus_val(nk, k, res);
                else if(nlen-nk <= 1) usable = use_plus_val(pk, k, res);
                else use_norp_val(nk, pk, k, res);
            }
        }
    }
    

    cout << res << endl;
    return 0;

}

Measured memory_bytes: 5440