#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end(),greater<ll>())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll C(ll n, ll i)
{
    if(n<i) return 0;      
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}
int main() {
	//your code goes here
	IOS;
	ll n,m;       
	ll j,y,z,k,b,a,x,t,i;   
	 cin>>n>>k;
	 v<ll> pos,neg;
	 ll prod=1;
	 rep(i,n){
	       cin>>x;
	       prod*=x;
	       prod%=M;
	       if(x>=0){
	             pos.pb(x);

	       }
	       else{
	             neg.pb(abs(x));
	       }
	 }
	 sortv(pos); sortv(neg);
	 if(n==k){
	       
	       cout<<(prod%M+M)%M<<'\n';
	 }
	 else if(pos.size()==0){
	       ll p=1;
	       if(k%2==0){
	             for(i=0;i<k;i++){
	                   p*=neg[i];
	                   p%=M;
	             }
	             cout<<p%M;
	             
	       }
	       else{
	             for(i=0;i<k;i++){
	                   p*=neg[neg.size()-1-i];
	                   p%=M;
	             }
	             p*=-1;
	             cout<<(p%M+M)%M;
	       }
	 }
	 else{
	       ll p;
	       if(k%2==0){
	             p=1;
	             i=0;
	       }
	       else{
	             p=pos[0];
	             i=1;
	             k--;
	       }
	       j=0;
	       ll s1=pos.size(); ll s2=neg.size();
	       while(k>0){
	             if(i+1<s1&&j+1<s2){
	                   if(pos[i]*pos[i+1]<neg[j]*neg[j+1]){
	                         p*=neg[j];
	                         p%=M;
	                         p*=neg[j+1];
	                         p%=M;
	                         j+=2;
	                   }
	                   else{
	                         p*=pos[i];
	                         p%=M;
	                         p*=pos[i+1];
	                         p%=M;
	                         i+=2;
	                   }
	                   k-=2;
	                   continue;
	             }
	             if(i+1<s1){
	                   p*=pos[i];
	                   p%=M;
	                   p*=pos[i+1];
	                   p%=M;
	                   i+=2;
	                   k-=2;
	                   continue;
	             }
	             if(j+1<s2){
	                   p*=neg[j];
	                   p%=M;
	                   p*=neg[j+1];
	                   p%=M;
	                   j+=2;
	                   k-=2;
	                   continue;
	             }
	       }
	       cout<<p%M;
	 }
	 
	 
	return 0;
}

Measured memory_bytes: 5456