#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define com bool operator<(const node &b)
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int maxn = (ll) 3e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int T = 1;

void solve() {
    int n, k;
    cin >> n >> k;
    priority_queue<int> zheng;
    priority_queue<int, vector<int>, greater<>> fu;
    bool flag = false, flag1 = false, flag2 = false;
    rep(i, 1, n) {
        int x;
        cin >> x;
        if (x > 0)
            zheng.push(x), flag1 = true;
        else if (x == 0)
            flag = true;
        else
            fu.push(x), flag2 = true;
    }
    if (n == k) {
        if (flag) {
            cout << 0;
            return;
        }
        int ans = 1;
        while (!zheng.empty()) {
            ans = ans * zheng.top() % mod;
            zheng.pop();
        }
        while (!fu.empty()) {
            ans = ((ans * fu.top()) % mod + mod) % mod;
            fu.pop();
        }
        cout << ans;
        return;
    }
    if (zheng.size() + fu.size() < k) {
        cout << 0;
        return;
    }
    if (!flag1 && !flag2) {
        cout << 0;
        return;
    } else if (flag1 && !flag2) {
        int ans = 1;
        rep(i, 1, k) {
            ans *= zheng.top();
            zheng.pop();
            ans %= mod;
        }
        cout << ans;
        return;
    } else if (!flag1 && flag2) {
        if ((k & 1) && flag) {
            cout << 0;
            return;
        } else if (k & 1) {
            while (fu.size() > k)
                fu.pop();
            int ans = 1;
            rep(i, 1, k) {
                ans *= fu.top();
                fu.pop();
                ans = (ans % mod + mod) % mod;
            }
            cout << ans;
            return;
        }
        int ans = 1;
        rep(i, 1, k) {
            ans *= fu.top();
            fu.pop();
            ans = (ans % mod + mod) % mod;
        }
        cout << ans;
        return;
    }
    int ans = 1;
    while (k > zheng.size() && fu.size() >= 2) {
        k -= 2;
        ans = (ans * fu.top() % mod + mod) % mod;
        fu.pop();
        ans = (ans * fu.top() % mod + mod) % mod;
        fu.pop();
    }
    if (k > zheng.size()) {
        cout << 0;
        return;
    }
    while (k) {
        if (k == 1) {
            if (zheng.empty()) {
                cout << 0;
                return;
            }
            ans = ans * zheng.top() % mod;
            break;
        }
        if (fu.size() < 2) {
            while (!zheng.empty() && k--) {
                ans = ans * zheng.top() % mod;
                zheng.pop();
            }
            if (k > 0) {
                cout << 0;
                return;
            }
            break;
        }
        int fu1, fu2;
        fu1 = fu.top();
        fu.pop();
        fu2 = fu.top();
        fu.pop();
        int zheng1, zheng2;
        zheng1 = zheng.top();
        zheng.pop();
        zheng2 = zheng.top();
        zheng.pop();
        if (zheng1 * zheng2 <= fu1 * fu2) {
            ans = (ans * fu1 % mod + mod) % mod;
            ans = (ans * fu2 % mod + mod) % mod;
            zheng.push(zheng1);
            zheng.push(zheng2);
            k -= 2;
        } else {
            ans = ans * zheng1 % mod;
            zheng.push(zheng2);
            fu.push(fu1);
            fu.push(fu2);
            --k;
        }
    }
    cout << ans % mod;
}

signed main() {
    start;
    while (T--)
        solve();
    return 0;
}

Measured memory_bytes: 5504