#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


void solve()
{
   
   int n,k;
   cin >> n >> k;

   int an = 0,fl=0;
   int a[n];
   vii pos,neg;

   forf(i,0,n)
   {
      int el;
      cin >> el;
      a[i] = el;
      if(el==0) fl=1;
      if(el < 0) neg.pb(el);
      else if(el > 0 ) pos.pb(el);

   }

   if(k > sz(neg) + sz(pos))
   {
    cout<<"0\n";
    return ;
   }

   if(k==n)
   {
    an = 1;
    forf(i,0,n)
    {
        an = ((a[i]+M)%M * (an%M))%M;
    }
    cout<<an;
    return;
   }

   sort(pos.begin(),pos.end());
   sort(neg.begin(),neg.end());

   if(k&1 && sz(pos) == 0 )
   {
       if(fl) 
       {
        cout<<"0\n";
        return ;
       }
       int an = 1;
       
       rv(neg);

       forf(i,0,k)
       {

         an = ((an%M)* (neg[i]%M+M)%M)%M;
       }
      cout<<an;
      return ;
   }

   rv(pos);
   
   int sp = sz(pos) , sn = sz(neg);

   an = 1;


   int it1 = 0 , it2 =0 ;
   if(k%2!=0) it1 =1 ,k--,an = pos[0];



  while(k>0)
  {
    if(it1 + 2 <= sp && it2 + 2 <= sn)
    {
      int f1 = pos[it1] * pos[it1+1];
      int f2 = neg[it2] * neg[it2+1];
      //cout<<f1<<" "<<f2<<"\n";
      if(f1 < f2 || (f1 == f2 && sn-it2 >  sp-it1)) an = ((an%M)%M * (f2%M))%M , it2+=2,k-=2;
      else an = ((an%M)%M * (f1%M))%M , it1+=2,k-=2;
    }else if(it1+2 <= sp)
    {
      int f1 = pos[it1] * pos[it1+1];
      
      an = ((an%M)%M * (f1%M))%M , it1+=2,k-=2;       
    } 
    else if(it1+2 <= sn)
    {
       int f2 = neg[it2] * neg[it2+1];
       an = ((an%M)%M * (f2%M))%M , it2+=2,k-=2;
    }else
    {
      if(fl==1)
      {
        cout<<"0\n";
        return ;
      }
      an = ((an%M) * (pos[sp-1]%M))%M;
      an = ((an%M) * ((neg[sn-1]%M+M)%M))%M;
      sn--;
      sp--;
      k-=2;

    }
  }

   cout<<an;

}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 6696