#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;

const int mod = 1000000007;
//const int mod = 998244353;
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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
    
int main(){
    int n, k;
    cin >> n >> k;
    //priority_queue<ll, vector<ll>, less<ll>> a_plus, a_minus;
    vector<ll> a_plus, a_minus;

    rep(i,n){
        ll a;
        cin >> a;
        if(a<0){
            a *= -1;
            a_minus.push_back(a);
        } else {
            a_plus.push_back(a);
        }
    }

    int plen = a_plus.size();
    int mlen = a_minus.size();
    int kcheck = k;
    bool great = false;
    mlen = min(mlen,kcheck);
    if(mlen%2) kcheck++;
    if(kcheck-mlen<=plen){
        great = true;
        sort(a_plus.rbegin(), a_plus.rend());
        sort(a_minus.rbegin(), a_minus.rend());
    } else{
        sort(a_plus.begin(), a_plus.end());
        sort(a_minus.begin(), a_minus.end());
    }

    int aix = 0, bix = 0;

    auto comp = [&](){
        bool a = aix <= a_plus.size()-2;
        bool b = bix <= a_minus.size()-2;
        if(a_plus.empty()) a = false;
        if(a_minus.empty()) b = false;
        if(a&&b){ 
            ll p = a_plus[aix]*a_plus[aix+1];
            ll m = a_minus[bix]*a_minus[bix+1];
            if(great){
                if(p>=m){
                    aix += 2;
                    return p;
                } else {
                    bix += 2;
                    return m;
                }
            } else{
                if(p<=m){
                    aix += 2;
                    return p;
                } else {
                    bix += 2;
                    return m;
                }
            }
        } else if(a){
            ll p = a_plus[aix]*a_plus[aix+1];
            aix += 2;
            return p;
        } else if(b){
            ll m = a_minus[bix]*a_minus[bix+1];
            bix += 2;
            return m;
        } else{
            return a_plus[aix]*a_minus[bix]*(-1);
        }
    };

    mint ans = 1;
    if(k&1){
        if(great){
            mint a;
            a = (mint)a_plus[aix];
            aix++;
            ans *= a;
            k -= 1;
        }
        else{
            ans *= -1;
            if(a_plus.empty()){
                ans *= (mint)a_minus[bix];
                bix++;
            } else if(a_plus[aix]<a_minus[bix]){
                ans *= (mint)a_plus[aix];
                aix++;
            } else{
                ans *= (mint)a_minus[bix];
                bix++;
            }
            k-= 1;
        } 
    }
    for(int i=k; i>0; i-=2){
        mint l;
        l = (mint)comp();
        ans *= l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5536