/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int mod = 1e9+7;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}
const int N = 2e6+5;

int32_t main(){
   
   speed_cubing
   
   int n,k;
   cin>>n>>k;

   vector<int> a(n);

   for(int i=0;i<n;i++)
      cin>>a[i];

   bool temp1 = 0,temp2 = 0;   

   vector<pll> v;

   for(auto x:a){
      if(x<0)
        v.pb({-x,-1});
      else if(x>0)
        v.pb({x,1}),temp1 = 1;
      else   
        temp2 = 1;
   }

   sort(v.begin(),v.end());

   if(temp1==0 && k%2==1){
     if(temp2==1)
       cout<<0;
     else{
       int sum = 1;
       for(int i=0;i<k;i++)
          sum*=v[i].ff*-1,sum%=mod;
       if(sum<0)
         sum+=mod;
       cout<<sum;       
     }   
     return 0;
   }

   reverse(v.begin(),v.end());

   int sz = v.size();

   if(sz<k){
     cout<<0;
     return 0; 
   }

   bool flag = 0;
   int pro = 1;
   int minus = 0,plus = 0;

   for(int i=0;i<k;i++){

      if(v[i].ss<0){
        pro*=v[i].ff*-1; 
        flag ^= 1; 
        minus = v[i].ff*-1;
      }
      else{
        pro*=v[i].ff;
        plus = v[i].ff;
      }
     
      pro%=mod;    
   
   }

   if(!flag){
     if(pro<0)
       pro+=mod;
     cout<<pro;
     return 0;   
   }

   if(sz==k){

     if(n>k)
       cout<<0;
     else if(n==k){
       if(pro<0)
         pro+=mod;
       cout<<pro;   
     }    

     return 0;
   }

   // cout<<pro<<' '<<plus<<' '<<minus<<endl;
   
   vector<pll> vv;

   for(int i=k;i<sz;i++){
      // cout<<v[i].ff<<endl;
      if(v[i].ss<0 && plus!=0){
        vv.pb({plus,v[i].ff*-1}); 
      //   cout<<32<<' '<<vv.back().ss<<endl;
        plus = 0;
      }
      else if(v[i].ss>0 && minus!=0){
        vv.pb({minus,v[i].ff});
      //   cout<<64<<' '<<vv.back().ss<<endl;
        minus = 0;
      }
   }

   // cout<<vv.size()<<endl;

   if(vv.size()==1){
     
     pro*=mul_inv((vv[0].ff+mod)%mod); 
     pro%=mod;
     pro*=vv[0].ss;
     pro%=mod;
     
     if(pro<0)
       pro+=mod;

     cout<<pro;
     return 0;  

   }
   else if(vv.size()==2){

   //   cout<<vv[0].ss<<' '<<vv[0].ff<<endl;
   //   cout<<vv[1].ss<<' '<<vv[1].ff<<endl;

     if((ll)abs(vv[0].ss)*(ll)abs(vv[1].ff) <= (ll)abs(vv[1].ss)*(ll)abs(vv[0].ff))
       reverse(vv.begin(),vv.end());

   }
   else{
     cout<<0;
     return 0;   
   }

   pro*=mul_inv((vv[0].ff+mod)%mod); 
   pro%=mod;
   pro*=vv[0].ss;
   pro%=mod;
     
   if(pro<0)
     pro+=mod;

   cout<<pro;

   return 0;
}

Measured memory_bytes: 8936