#include <bits/stdc++.h>
using namespace std;

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<pair<int,int>> A(N);
    for (int i=0;i<N;i++) {
        int a;
        cin >> a;
        if (a > 0) A.emplace_back(a, 1);
        if (a == 0) A.emplace_back(0, 0);
        if (a < 0) A.emplace_back(-a, -1);
    }
    sort(A.rbegin(),A.rend());
    mint ans = 1;
    int minus = 0;
    int finalplus = -1;
    int finalminus = -1;
    for (int i=0;i<K;i++){
        ans *= A[i].first;
        if (A[i].second <0) {
            minus++;
            finalminus = i;
        }
        if (A[i].second >0) finalplus = i;
    }
    if (minus % 2 == 0){
        cout << ans << "\n";
        return 0;
    } else {
        int nextplus = -1;
        int nextminus = -1;
        for (int i=K;i<N;i++){
            if (A[i].second > 0 && nextplus == -1) {
                nextplus = i;
            }
            if (A[i].second < 0 && nextminus == -1){
                nextminus = i;
            }
        }
        bool flag1 = true;
        bool flag2 = true;
        pair<ll,ll> change1 = make_pair(-1,-1);
        pair<ll,ll> change2 = make_pair(-1,-1);
        if (finalplus != -1 && nextminus != -1) {
            change1 = make_pair(A[finalplus].first,A[nextminus].first);
        } else {
            flag1 = false;
        }
        if (finalminus != -1 && nextplus != -1) {
            change2 = make_pair(A[finalminus].first,A[nextplus].first);
        } else {
            flag2 = false;
        }
        if (flag1 && flag2) {
            if (change1.first*change2.second > change2.first*change1.second){
                ans /= A[finalminus].first;
                ans *= A[nextplus].first;
                cout << ans << "\n";
                return 0;
            } else {
                ans /= A[finalplus].first;
                ans *= A[nextminus].first;
                cout << ans << "\n";
                return 0;
            }
        } else if (flag1){
            ans /= A[finalplus].first;
            ans *= A[nextminus].first;
            cout << ans << "\n";
            return 0;
        } else if (flag2){
            ans /= A[finalminus].first;
            ans *= A[nextplus].first;
            cout << ans << "\n";
            return 0;
        } else {
            // 絶対値の小さい方からかける
            ans = 1;
            for (int i=0;i<K;i++){
                ans *= A[N-1-i].first;
            }
            ans *= -1;
            cout << ans << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 6344