#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
 
ll p=1e9+7; 

void func()
{
   ll n,k;
   cin>>n>>k;
   ll arr[n+1];
   f(i,1,n+1) cin>>arr[i];
   vector<pll> v;
   ll cnt0=0;
   f(i,1,n+1) 
   {
	   if(arr[i]>0) v.pb(MP(arr[i],i));
	   else if(arr[i]<0) v.pb(MP(-arr[i],i));
	   else cnt0++;
   }
   
   sort(ALL(v));
   reverse(ALL(v));
   
   
   if(sz(v)<k) 
   {
	   cout<<"0\n";
	   return;
   }
   
   ll cntp=0,cntn=0;
   f(i,0,k) 
   {
	   ll ss=(arr[v[i].S]>0);
	   if(ss) cntp++;
	   else cntn++;
   }
   
   if(cntn%2==0)
   {
	   ll ans=1;
	   f(i,0,k) ans=(ans*v[i].F)%p;
	   cout<<ans<<endl;
	   return;
   } 
   
   
   vll pp,qq;
   f(i,k,sz(v)) 
   {
	   ll ss=(arr[v[i].S]>0);
	   if(ss) pp.pb(v[i].F);
	   else qq.pb(v[i].F);
   }

   ll worstp=infl,idx1=-1,worstn=infl,idx2=-1;
   f(i,0,k) 
   {
	   ll ss=(arr[v[i].S]>0);
	   if(ss) 
	   {
		   if(v[i].F<worstp) 
		   {
			   worstp=v[i].F;
			   idx1=i;		   
		   }
	   }
	   
	   else 
	   {
		   if(v[i].F<worstn)
		   {
			   worstn=v[i].F;
			   idx2=i;
		   }
	   }
   }

   
   bool flag=0;
   ll tt=-1,uu=-1;
   if(sz(pp)!=0) // remove worst -ve and add best positive
   {
	   tt=pp[0];
	   flag=1;
   }
   if(cntp>0 && sz(qq)!=0) // remove worst +ve and add best negative
   {
	   uu=qq[0];
	   flag=1;
   }
   
   
   
   if(!flag) // can't make +ve product
   {
	   if(cnt0>0) 
	   {
		   cout<<"0\n";
		   return;
	   }
	   
	   reverse(ALL(v));
	   ll ans=1;
	   f(i,0,k) 
	   {
		   ans=(ans*v[i].F)%p;
	   }
	   ans*=(-1);
	   ans=(ans+p)%p;
	   cout<<ans<<endl;
	   return;
   }
   
   if(tt==-1)
   {
	   ll ans=qq[0]%p;
	   f(i,0,k)
	   {
		   if(i==idx1) continue;
		   ans=(ans*v[i].F)%p;
	   }
	   
	   cout<<ans<<endl;
	   return;
   }
   
   if(uu==-1)
   {
	   ll ans=pp[0]%p;
	   f(i,0,k)
	   {
		   if(i==idx2) continue;
		   ans=(ans*v[i].F)%p;
	   }
	   
	   cout<<ans<<endl;
	   return;
   }
   
   if(pp[0]*worstp>qq[0]*worstn)
   {
	   ll ans=pp[0]%p;
	   f(i,0,k)
	   {
		   if(i==idx2) continue;
		   ans=(ans*v[i].F)%p;
	   }
	   
	   cout<<ans<<endl;
   }
   
   else
   {
	   ll ans=qq[0]%p;
	   f(i,0,k)
	   {
		   if(i==idx1) continue;
		   ans=(ans*v[i].F)%p;
	   }
	   
	   cout<<ans<<endl;
   }
   
}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }
     
    return 0;
}


Measured memory_bytes: 8976