/**
*    author:  boutarou
*    created: 05.07.2020 21:50:36
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;
const lint MOD = 1e9 + 7;

long long mod_pow(long long n, long long p, long long m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}

long long modinv(long long a, long long mod) {
    return mod_pow(a, mod - 2, mod);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    lint n, K;
    cin >> n >> K;
    vector<lint> a(n);
    vector<pair<lint, bool>> p(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] >= 0) p[i] = {abs(a[i]), true};
        else p[i] = {abs(a[i]), false};
    }
    sort(p.rbegin(), p.rend());
    lint ans = 1;
    bool plus = true;
    rep(i, K) {
        ans *= p[i].first;
        ans %= MOD;
        if (!p[i].second) {
            if (plus) plus = false;
            else plus = true;
        }
    }
    if (plus) {
        cout << ans << endl;
        return 0;
    }
    vector<pair<lint, lint>> vec;
    {
        int minus_max = -1;
        int plus_min = -1;
        rep(i, K) {
            if (!p[i].second) minus_max = i;
        }
        for (int i = K; i < n; i++) {
            if (p[i].second) {
                plus_min = i;
                break;
            }
        }
        if (plus_min != -1 && minus_max != -1) {
            vec.push_back({p[minus_max].first, p[plus_min].first});
        }
    }
    {
        int plus_max = -1;
        int minus_min = -1;
        rep(i, K) {
            if (p[i].second) plus_max = i;
        }
        for (int i = K; i < n; i++) {
            if (!p[i].second) {
                minus_min = i;
                break;
            }
        }
        if (minus_min != -1 && plus_max != -1) {
            vec.push_back({p[plus_max].first, p[minus_min].first});
        }
    }
    if (vec.empty()) {
        reverse(p.begin(), p.end());
        lint nans = 1;
        rep(i, K) {
            if (p[i].second) nans *= p[i].first;
            else nans *= p[i].first * -1;
            nans %= MOD;
        }
        if (nans < 0) nans += MOD;
        cout << nans << endl;
    }
    else if (vec.size() == 1) {
        ans *= modinv(vec[0].first, MOD);
        ans %= MOD;
        ans *= vec[0].second;
        ans %= MOD;
        if (ans < 0) ans += MOD;
        cout << ans << endl;
    }
    else {
        lint a = vec[0].second, b = vec[0].first;
        lint c = vec[1].second, d = vec[1].first;
        if (a * d >= b * c) {
            ans *= modinv(vec[0].first, MOD);
            ans %= MOD;
            ans *= vec[0].second;
            ans %= MOD;
            if (ans < 0) ans += MOD;
            cout << ans << endl;
        }
        else {
            ans *= modinv(vec[1].first, MOD);
            ans %= MOD;
            ans *= vec[1].second;
            ans %= MOD;
            if (ans < 0) ans += MOD;
            cout << ans << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 7952