#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
#define mod1 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll> ar(n);
    ll ans=1;
    vector<ll> pos,neg;
    for(ll x=0;x<n;x++){
        cin>>ar[x];
        if(ar[x]>=0){
            pos.push_back(ar[x]);
        }else{
            neg.push_back(ar[x]);
        }
    }
    bool ans_neg=true;
    for(ll y=0;y<=n;y+=2){
        if(y>neg.size())break;
        ll rem=k-y;
        if(rem<=pos.size()){
            ans_neg=false;
            break;
        }
    }
    // deb(ans_neg);
    sort(pos.begin(),pos.end());
    sort(neg.rbegin(),neg.rend());
    if(ans_neg){
        ll ni=0,pi=0;
        while(k--){
            if(ni<neg.size() && pi<pos.size()){
                if(abs(neg[ni])<=abs(pos[pi])){
                    ans*=neg[ni];
                    ni++;
                }else{
                    ans*=pos[pi];
                    pi++;
                }
            }else if(ni<neg.size()){
                ans*=neg[ni];
                ni++;
            }else if(pi<pos.size()){
                ans*=pos[pi];
                pi++;
            }
            ans%=mod;
        }
    }else{
        ll ni=neg.size();
        ni--;
        ll pi=pos.size();
        pi--;
        while(k>=2){
            if(ni>=1 && pi>=1){
                ll np=neg[ni]*neg[ni-1];
                ll pp=pos[pi]*pos[pi-1];
                if(np>=pp){
                    np%=mod;
                    ans*=np;
                    ans%=mod;
                    ni-=2;
                }else{
                    pp%=mod;
                    ans*=pp;
                    ans%=mod;
                    pi-=2;
                }
                k-=2;
            }else if(pi>=1){
                ll pp=pos[pi]*pos[pi-1];
                pp%=mod;
                ans*=pp;
                ans%=mod;
                pi-=2;
                k-=2;
            }else if(ni>=1){
                ll np=neg[ni]*neg[ni-1];
                np%=mod;
                ans*=np;
                ans%=mod;
                ni-=2;
                k-=2;
            }else{
                ans*=pos[pi--];
                ans%=mod;
                ans*=neg[ni--];
                ans%=mod;
                k-=2;
            }
        }
        if(k){
            if(pi>=0){
                ans*=pos[pi--];
                ans%=mod;
            }else{
                ans*=neg[ni--];
                ans%=mod;
            }
            k--;
        }
    }
    
    ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 6940