#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

signed main(){
    ll n,k;
    cin >> n >> k;
    ll a[n] = {};
    vector<ll> vec_pos,vec_neg;
    rep(i,0,n){
        cin >> a[i];
        if(a[i] < 0){
            vec_neg.push_back(a[i]);
        }
        else{
            vec_pos.push_back(a[i]);
        }
    }
    if(n == 1){
        cout << a[0] << endl;
    }

    sort(vec_pos.begin(),vec_pos.end(),greater<ll>());
    sort(vec_neg.begin(),vec_neg.end());

    if(vec_pos.size() == 0 && k % 2 == 1){
        mint ans = 1;
        sort(a,a+n,greater<ll>());
        rep(i,0,k){
            ans *= a[i];
        }
        cout << ans << endl;
    }
    else if(n == k && vec_neg.size() % 2 == 1){
        mint ans = 1;
        rep(i,0,n){
            ans *= a[i];
        }
        cout << ans << endl;
    }
    else{
        mint ans = 1;
        ll pindex = 0,nindex = 0;
        while(k){
            if(k >= 2 && pindex+1 < vec_pos.size() && nindex+1 < vec_neg.size()){
                ll ptmp = vec_pos[pindex] * vec_pos[pindex+1];
                ll ntmp = vec_neg[nindex] * vec_neg[nindex+1];
                if(ntmp >= ptmp){
                    ans *= ntmp;
                    nindex += 2;
                }
                else{
                    ans *= ptmp;
                    pindex += 2;
                }

                k -= 2;
            }
            else if(k >= 2 && nindex+1 < vec_neg.size()){
                ans *=  vec_neg[nindex] * vec_neg[nindex+1];
                nindex += 2;
                k -= 2;
            }
            else if(pindex < vec_pos.size() ){
                ans *= vec_pos[pindex];
                pindex++;
                k--;
            }
            else if(nindex < vec_neg.size()){
                ans *= vec_neg[nindex];
                nindex++;
                k--;
            }
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 6860