#include <bits/stdc++.h>
#define DBG2

using namespace std;

long long N, K;
vector <long long> A;
const long long MOD = 1000000000 + 7;

struct NNUM{
    long long origin;
    long long abs;
    bool operator< (const NNUM& another) const{
        return (abs == another.abs) ? (origin < another.origin) : (abs < another.abs);
    }
};

vector<NNUM> B;

long long modmult(long long a, long long b, long long m){
    long long ta = (a < 0) ? -a : a;
    long long tb = (b < 0) ? -b : b;
    long long mul = (ta * tb) % MOD;
    if((a < 0) && (b < 0)){
        return mul;
    } else if((a > 0) && (b > 0)){
        return mul;
    } else if(mul == 0){
        return 0;
    } else {
        return MOD - mul;
    }
}

int main(){
    cin >> N >> K;
    cin.ignore();

    bool allnotminus = true; // すべて非負整数か
    bool allnotpls = true; // すべて非正整数か
    bool detected_zero = false; // 0が存在するか


    for(int i = 0; i < N; i++){
        long long tmp;
        cin >> tmp;
        A.push_back(tmp);
        if(tmp < 0){
            allnotminus = false;
        }
        if(tmp > 0) allnotpls = false;
    }
    cin.ignore();

    if(allnotminus){ // すべて正のときは単純
        sort(A.begin(), A.end());
        long long ans = 1;
        for(int i = 0; i < K; i++){
            ans *= A[N-1-i];
            ans %= MOD;
        }
        cout << ans << endl;
        return 0;
    }

    // 全て非正整数のとき
    if(allnotpls){
        sort(A.begin(), A.end());
        if(K%2==0){
            long long ans = 1;
            for(int i = 0; i < K; i+=2){
                ans *= -A[i];
                ans %= MOD;
                ans *= -A[i+1];
                ans %= MOD;
            }
            cout << ans << endl;
            return 0;
        } else {
            if(detected_zero){
                cout << 0 << endl;
                return 0;
            }
            long long ans = 1;
            for(int i = 0; i < K; i++){
                ans = modmult(ans, A[N-1-i], MOD);
            }
            cout << ans << endl;
            return 0;
        }
    }

    for(int i = 0; i < N; i++){
        NNUM tmp;
        tmp.origin = A[i];
        tmp.abs = (A[i] < 0) ? -A[i] : A[i];
        B.push_back(tmp);
    }
    sort(B.begin(), B.end());

    long long ans = 1;
    long long nminus_ = 0;
    for(int i = 0; i < K; i++){
        #ifdef DBG
        cout << "B[N-1-i].abs = " << B[N-1-i].abs << endl;
        #endif
        ans *= B[N-1-i].abs;
        ans %= MOD;
        if(B[N-1-i].origin < 0){
            ++nminus_;
        }
    }
    if(nminus_ % 2 == 0){
        cout << ans << endl;
        return 0;
    }
    if(N==K){
        ans = 1;
        for(int i = 0; i < K; i++){
            //ans *= B[i].abs;
            //ans %= MOD;
            ans = modmult(ans, A[i], MOD);
        }
        cout << ans << endl;
        return 0;
    }
    if(ans == 0){ // すでに0だった
        cout << ans << endl;
        return 0;
    }

    ans = 1;

    // 最小の負と正を見つける
    long long m_rem;
    long long m_rem_idx;
    long long m_ad;
    long long m_ad_idx;
    bool m_found = false;
    if(nminus_ != 0){
        for(int i = N-K; i < N; i++){
            if(B[i].origin < 0){
                m_found = true;
                m_rem_idx = i;
                m_rem = B[i].abs;
                break;
            }
        }
        if(!m_found) goto M_NT_FOUND; // ありえない
        m_found = false;
        for(int i = N-K-1; i >= 0; i--){
            if(B[i].origin >= 0){
                m_found = true;
                m_ad = B[i].abs;
                m_ad_idx = i;
                break;
            }
        }
    }
M_NT_FOUND:
    long long p_rem;
    long long p_rem_idx;
    long long p_ad;
    long long p_ad_idx;
    bool p_found = false;
    {
        for(int i = N-K; i < N; i++){
            if(B[i].origin > 0){
                p_found = true;
                p_rem_idx = i;
                p_rem = B[i].abs;
                break;
            }
        }
        if(!p_found) goto P_NT_FOUND;
        p_found = false;
        for(int i = N-K-1; i >= 0; i--){
            if(B[i].origin < 0){
                p_found = true;
                p_ad = B[i].abs;
                p_ad_idx = i;
                break;
            }
        }
    }
P_NT_FOUND:
    // p_ad / p_rem > m_ad / m_rem <=> p_ad * m_rem > p_rem * m_ad
    ans = 1;

    if(!p_found) {
        for(int i = N - 1; i >= N-K; i--){
            if(i == m_rem_idx) continue;
            ans *= B[i].abs;
            ans %= MOD;
        }
        ans *= m_ad;
        ans %= MOD;
        cout << ans << endl;
        return 0;
    }
    if(!m_found){
        for(int i = N - 1; i >= N-K; i--){
            if(i == p_rem_idx) continue;
            ans *= B[i].abs;
            ans %= MOD;
        }
        ans *= p_ad;
        ans %= MOD;
        cout << ans << endl;
        return 0;
    }
    if(p_ad )
    if(!m_found || (p_rem != 0) && (p_ad * m_rem > p_rem * m_ad)){
        for(int i = N - 1; i >= N-K; i--){
            if(i == p_rem_idx) continue;
            ans *= B[i].abs;
            ans %= MOD;
        }
        ans *= p_ad;
        ans %= MOD;
        cout << ans << endl;
        return 0;
    } else {
        for(int i = N - 1; i >= N-K; i--){
            if(i == m_rem_idx) continue;
            ans *= B[i].abs;
            ans %= MOD;
        }
        ans *= m_ad;
        ans %= MOD;
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 8900