#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e18+5;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    ll n,k;
    cin>>n>>k;
    vl p,neg;
    ll mx = -infL,all=1;
    int u[2]={};
    forn(i,0,n){
        ll a;
        cin>>a;
        if(a>=0){
            p.pb(a);
        }
        else{
            neg.pb(a);
        }
        mx = max(mx,a);
        all = (all*a)%MOD;
        all = (all+MOD)%MOD;
        u[(a>=0)]++;
    }
    sort(p.begin(),p.end());
    sort(neg.begin(),neg.end());
    if(u[0]==n and k%2==1){
        ll ans = 1,taken=0,i=n-1;
        while(taken<k){
            ++taken;
            ans = (ans*(neg[i--]+MOD))%MOD;
        }
        cout<<ans;
        return 0;
    }
    if(u[0]==n){
        ll ans = 1,taken =0,i = 0;
        while(taken<k){
            ++taken;
            ans = (ans*(neg[i++]+MOD))%MOD;
        }
        cout<<ans;
        return 0;
    }
    if(k==1){
        cout<<(mx+MOD)%MOD;
        return 0;
    }
    if(k == n){
        cout<<all;
        return 0;
    }
    int i = p.size(),j = 0;
    --i;
    ll ans = 1;
    int taken = 0,cnt=0,pcnt=0;
    while(i>=0 and j<(int)neg.size() and taken<k){
        ++taken;
        if(p[i]>=abs(neg[j])){
            ++pcnt;
            ans = (ans*p[i])%MOD;
            --i;
        }
        else{
            ans = (ans*neg[j])%MOD;
            ++j;
            ans = (ans+MOD)%MOD;
            ++cnt;
        }
    }
    while(i>=0 and taken<k){
        ++taken;
        ++pcnt;
        ans = (ans*p[i])%MOD;
        --i;
    }
    while(j<(int)neg.size() and taken<k){
        ans = (ans*neg[j])%MOD;
        ++taken;
        // debug(neg[j]);
        ++j;
        ans = (ans+MOD)%MOD;
        ++cnt;
    }
    // debug(ans);
    if(cnt%2==1 and pcnt>0){
        ll a1 = -infL,a2 = -infL;
        if(j<neg.size()){
            a1 = neg[j-1]*neg[j];
        }
        if(i>=0){
            a2 = p[i]*p[i+1];
        }
        if(a1<a2){
            ans = (ans*mod_inv(neg[j-1]+MOD,MOD))%MOD;
            ans = (ans*p[i])%MOD;
        }
        else{
            ans = (ans*mod_inv(p[i+1],MOD))%MOD;
            ans = (ans*neg[j])%MOD;
            ans = (ans+MOD)%MOD;
        }
    }
    if(cnt%2==1 and pcnt==0){
        if(i>=0){
            ans = (ans*mod_inv(neg[j-1]+MOD,MOD))%MOD;
            ans = (ans*p[i])%MOD;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5560