//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<unordered_map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<memory>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)   a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    //
    ModInt operator++(int) {
        auto t = *this;
        *this += 1;
        return t;
    }

    ModInt operator--(int) {
        auto t = *this;
        *this -= 1;
        return t;
    }
    ModInt operator<<(const int n){
        return ModInt(*this)*ModInt(2).pow(n);
    }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
    ll N; cin >> N;
    ll sum =0;
    while(sum<N){
        sum+=1000;
    }
    cout << sum-N << endl;
}

void b(){
    ll N; cin >> N;
    unordered_map<string,ll> ANS;
    rep(i,N){
        string s; cin >> s;
        ANS[s]++;
    }
    cout << "AC x " << ANS["AC"]<<endl;

    cout << "WA x " << ANS["WA"]<<endl;

    cout << "TLE x " << ANS["TLE"]<<endl;

    cout << "RE x " << ANS["RE"]<<endl;


}

void c(){
    ll H,W,K; cin >> H >> W >> K;
    string C[H];
    
    rep(i,H){
        cin >> C[i];
    }
    
    ll ans=0;
    
    rep(i,1<<H){
        rep(j,1<<W){
            ll cnt=0;
            rep(s,H) rep(t,W){
                if(((i>>s)&1)==0&&((j>>t)&1)==0){
                    if(C[s][t]=='#')cnt++;
                }
            }
            if(cnt==K)ans++;
        }
    }
    
    cout << ans << endl;


}

void d(){
    ll N; cin >> N;
    ll ans=0;
    v<> A(N,0);
    rep(i,N){
        cin >> A[i];
    }
    sort(all(A),greater<ll>());
    for(ll i=1;i<N-1;i++){
        ans+=A[(i+1)/2];
    }
    ans+=A[0];
    cout << ans <<endl;
}

void e(){
    ll N,K; cin >> N >> K;
    auto S = v<>();
    auto T = v<>();
    auto A = v<>(N,0);
    rep(i,N){
        cin >> A[i];
        if(A[i]<0) T.push_back(A[i]);
        else S.push_back(A[i]);
    }

    bool ok=true;
    if(S.size()>0){
        if(N==K) ok=(T.size()%2==0);
        else ok=true;
    }else{
        ok=(K%2==0);
    }
    
    mint ans=1;

    if(!ok){
        sort(all(A),greater<ll>());
        rep(i,K) ans*=A[i];
        cout << ans;
    }else{
        sort(all(S));
        sort(all(T),greater<ll>());

        auto F = v<>();
        if(K%2){
            ans*=S.back();S.pop_back();
        }

        while(S.size()>=2){
            ll t =S.back(); S.pop_back();
            t*=S.back();S.pop_back();
            F.push_back(t);
        }

        while(T.size()>=2){
            ll t =T.back(); T.pop_back();
            t*=T.back();T.pop_back();
            F.push_back(t);
        }
        sort(all(F),greater<ll>());
        rep(i,K/2) ans*=F[i];
        cout << ans<<endl;
    }

}

int main(){
    e();
}

Measured memory_bytes: 8108