#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int K, N;
ll A[200009];

pair<ll, ll> B[200009];

int main() {
    cin >> N >> K;
    REP(i, N) cin >> A[i];

    int cnt_pos=0, cnt_zero=0, cnt_neg=0;

    REP(i, N) {
        if (A[i] > 0) {
            B[i] = MP(A[i], 1);
            cnt_pos++;
        }
        else if (A[i] == 0) {
            B[i] = MP(0, 0);
            cnt_zero++;
        }
        else {
            B[i] = MP(-A[i], -1);
            cnt_neg++;
        }
    }

    sort(B, B + N, greater<pair<ll, ll>>());

    int cnt_posk=0, cnt_zerok=0, cnt_negk=0;
    REP(i, K) {
        if (B[i].second == 1) cnt_posk++;
        else if (B[i].second == 0) cnt_zerok++;
        else cnt_negk++;
    }

    ll ans = 1;
    if (cnt_negk % 2 == 0) {
        REP(i, K) ans = ans * B[i].first % MOD;
    }
    // -が奇数
    else {
        if (cnt_pos == 0) {
            if (cnt_zero > 0) ans = 0;
            else {
                REP(i, K) ans = ans * B[N-i-1].first * (-1) % MOD;
            }
        }
        else {
            if (cnt_pos == cnt_posk) {
                if (cnt_neg == cnt_negk) {
                    if (cnt_zero > 0) ans = 0;
                    else {
                        REP(i, K) ans = ans * B[i].first * B[i].second % MOD;
                    }
                }
                else {
                    int i = 0, j = 0;
                    while (j < cnt_posk-1) {
                        if (B[i].second == 1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                    i = 0, j = 0;
                    while (j < cnt_negk+1) {
                        if (B[i].second == -1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                }
            }
            else {
                if (cnt_posk == 0 || cnt_neg == cnt_negk) {
                    int i = 0, j = 0;
                    while (j < cnt_posk+1) {
                        if (B[i].second == 1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                    i = 0, j = 0;
                    while (j < cnt_negk-1) {
                        if (B[i].second == -1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                }
                else {
                    ll p1, n1, p2, n2;
                    int i = 0, j = 0;
                    while (j < cnt_posk+1) {
                        if (B[i].second == 1) {
                            p2 = p1;
                            p1 = B[i].first;
                            j++;
                        }
                        i++;
                    }
                    i = 0, j = 0;
                    while (j < cnt_negk+1) {
                        if (B[i].second == -1) {
                            n1 = n2;
                            n2 = B[i].first;
                            j++;
                        }
                        i++;
                    }
                    ll a = max(p1*p2, n1*n2);
                    a %= MOD;
                    i = 0, j = 0;
                    while (j < cnt_posk-1) {
                        if (B[i].second == 1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                    i = 0, j = 0;
                    while (j < cnt_negk-1) {
                        if (B[i].second == -1) {
                            ans = ans * B[i].first % MOD;
                            j++;
                        }
                        i++;
                    }
                    ans = ans * a % MOD;
                }
            }
        }
    }
    if (ans < 0) ans += MOD;
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 8324