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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#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 (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


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>;

int main(){ 
    ll n,k;
    cin >> n >> k;
    ll a[n] = {};

    ll p_cnt = 0,n_cnt = 0;
    rep(i,0,n){
        cin >> a[i];
        if(a[i] >= 0){
            p_cnt++;
        }
        else{
            n_cnt++;
        }
    }

    mint ans = 1;
    if(n == k){
        rep(i,0,n){
            ans *= a[i];
        }
    }
    else if(n_cnt == n && k % 2 == 1){ //答えが負
        priority_queue<ll, VECLL> n_pq;
        rep(i,0,n){
            n_pq.push(a[i]);
        }

        rep(i,0,k){
            ans *= n_pq.top();
            n_pq.pop();
        }
    }
    else{ //答えが正
        priority_queue<ll,VECLL, greater<ll>> n_pq;
        priority_queue<ll,VECLL> p_pq;
        rep(i,0,n){
            if(a[i] >= 0) p_pq.push(a[i]);
            else n_pq.push(a[i]);
        }

        while(k){
            if(k >= 2 && n_pq.size() >= 2){
                ll n1 = n_pq.top(); n_pq.pop();
                ll n2 = n_pq.top(); n_pq.pop();

                if(p_pq.size() < 2){
                    ans *= n1*n2;
                }
                else{
                    ll p1 = p_pq.top(); p_pq.pop();
                    ll p2 = p_pq.top(); p_pq.pop();

                    if(p1 * p2 > n1 * n2){
                        ans *= p1;
                        n_pq.push(n1);
                        n_pq.push(n2);
                        p_pq.push(p2);
                        k++;
                    }
                    else{
                        ans *= n1*n2;
                        p_pq.push(p1);
                        p_pq.push(p2);
                    }
                }
                k--;
            }
            else if(!p_pq.empty()){
                ans *= p_pq.top();
                p_pq.pop();
            }
            k--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6940