#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    vl sei={};
    vl fu={};
    for(auto p: A){
        if(p>=0)sei.emplace_back(p);
        else fu.emplace_back(p);
    }
    sort(sei.rbegin(), sei.rend());
    sort(fu.begin(), fu.end());
    if(sei.empty()){
        if(K%2==0){
            ll ans=1;
            for(ll i=0;i<K;++i){
                ans*=-fu[i];
                ans%=MOD;
            }
            prt(ans);return 0;
        }
        else {
            reverse(fu.begin(), fu.end());
            ll ans=1LL;
            for(ll i=0;i<K;++i){
                ans*=-fu[i];
                ans%=MOD;
                
            }
            prt((MOD-ans)%MOD);
                return 0;
        }
    }
    if(N==K){
        if(fu.size()%2==0){
            ll ans=1;
            for(auto p: sei){
                ans*=p;
                ans%=MOD;
            }
            for(auto p: fu){
                ans*=-p;
                ans%=MOD;
            }
            prt(ans);return 0;
        }
        else {
            ll ans=1;
            for(auto p: sei){
                ans*=p;
                ans%=MOD;
            }
            for(auto p: fu){
                ans*=-p;
                ans%=MOD;
            }
            prt((MOD-ans)%MOD);return 0;
        }
    }



    //debug(sei)debug(fu)
    ll seimark=min(K,(ll)sei.size());ll fumark=K-seimark;
    if(fumark%2==1){
        fumark++;
        seimark--;
    }
    //fuからi個
    while(fumark+2<=fu.size()&&seimark>=2){
        if(fu[fumark]*fu[fumark+1]>sei[K-fumark-2]*sei[K-fumark-1]){seimark-=2;fumark+=2;}
        else break;
    }
    ll ans=1LL;
    for(ll i=0;i<seimark;++i){
        ans*=sei[i];
        ans%=MOD;
    }
    for(ll i=0;i<fumark;++i){
        ans*=-fu[i];
        ans%=MOD;
    }
    prt(ans);

    return 0;
}



Measured memory_bytes: 6876