#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<llll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first;
        if(A[i].first >= 0){
            A[i].second = 1;
        }
        else{
            A[i].first = -A[i].first;
            A[i].second = -1;
        }
    }

    ll ans;
    sort(ALL(A), greater<llll> ());

    for (int i = 0; i < N; i++) {
        A[i].first = A[i].first * A[i].second;
    }

    //全部負の場合
    bool check = true;
    for (int i = 0; i < N; i++) {
        if(A[i].second == 1){
            check = false;
            break;
        }
    }
    if(check){
        if( K%2 == 1 ){
            ans = (A[N-1].first + MOD) % MOD;
            for (int i = 1; i < K; i++) {
                ans = ans * (A[N - 1 - i].first + MOD) % MOD;
            }
        }
        else{
            ans = 1;
            for (int i = 0; i < K; i++) {
                ans = ans * (A[i].first + MOD) % MOD;
            }
        }

        printf("%lld\n", ans);
        return 0;
    }

    //N=Kの場合
    if(N==K){
        ans = (A[0].first + MOD) % MOD;
        for (int i = 1; i < N; i++) {
            ans = ans * (A[i].first + MOD) % MOD;
        }
        printf("%lld\n", ans);
        return 0;
    }

    ll cnt = 0;
    for (int i = 0; i < K; i++) {
        if(A[i].second == -1){
            cnt++;
        }
    }

    ll idx1, idx2, idx3, idx4;
    ll ii, jj;
    ll tmp1, tmp2;
    if(cnt % 2 == 0){
        ans = (A[0].first + MOD) % MOD;
        for (int i = 1; i < K; i++) {
            ans = ans * (A[i].first + MOD) % MOD;
        }
    }
    else{
        idx1 = -1;
        for (int i = K-1; i >= 0; i--) {
            if(A[i].second == -1){
                idx1 = i;
                break;
            }
        }
        idx2 = N;
        for (int i = K; i < N; i++) {
            if(A[i].second == 1){
                idx2 = i;
                break;
            }
        }
        idx3 = -1;
        for (int i = K-1; i >= 0; i--) {
            if(A[i].second == 1){
                idx3 = i;
                break;
            }
        }        
        idx4 = N;
        for (int i = K; i < N; i++) {
            if(A[i].second == -1){
                idx4 = i;
                break;
            }
        }

        if(idx2 != N && idx3 != -1 && idx4 != N){
            tmp1 = A[idx2].first * A[idx3].first;
            tmp2 = A[idx1].first * A[idx4].first;
            if(tmp1 >= tmp2){
                ii = idx1;
                jj = idx2;
            }
            else{
                ii = idx3;
                jj = idx4;
            }
        }
        else if(idx2 == N){
            ii = idx3;
            jj = idx4;
        }
        else{
            ii = idx1;
            jj = idx2;
        }

        ans = 1;
        for (int i = 0; i < ii; i++) {
            ans = ans * (A[i].first + MOD) % MOD;
        }
        for (int i = ii+1; i < K; i++) {
            ans = ans * (A[i].first + MOD) % MOD;
        }
        ans = ans * (A[jj].first + MOD) % MOD;
       

    }

    printf("%lld\n", ans);

}   

Measured memory_bytes: 6368