/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#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>;
# define ll unsigned long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000007
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 1e9 + 7;
const int K = 2;
//typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}
*/

signed main() {
	gok

  int t=1;
 // cin>>t;

  while(t--)
  {
     int n,k;
     cin>>n>>k;
     int pr=k;
     int a[n];
     vector<int> v1,v2;
     for(int i=0;i<n;i++){
        cin>>a[i];
       if(a[i]<0)
            v2.push_back(a[i]);
       else
        v1.push_back(a[i]);
     }
     sort(v1.rbegin(),v1.rend());
     sort(v2.begin(),v2.end());

     //cout<<v2.size()<<endl;
     if(v1.size()==0)
     {
         if(k%2==1){
             int an=1;
             for(int i=v2.size()-1;i>=0&&k>0;i--)
             {
                 k--;
                 an *= (v2[i]+mod)%mod;
                // an += mod;
                 an %= mod;
             }
             cout<<(an+mod)%mod;
         }
         else
         {
            int an=1;
             for(int i=0;i<v2.size()&&k>0;i++)
             {
                 k--;
                 an *= (v2[i] + mod)%mod;
                // an += mod;
                 an %= mod;
             }
             cout<<an;
         }
     }
     else
     {
         if(k%2==1)
         {
            int an = v1[0];
            k--;
             int p1=1,p2=0;
             while(p1<(int)v1.size()-1 && p2<(int)v2.size()-1 && k>0)
             {
                 int pr1 = v1[p1]*v1[p1+1];
                 int pr2 = v2[p2]*v2[p2+1];
                 if(pr1>pr2)
                 {
                     an *= pr1%mod;
                     p1+=2;
                 }
                 else
                 {
                     an *= pr2%mod;
                     p2 += 2;
                 }
                 an %= mod;
                 k-=2;
             }
             if(k>0)
             {
                 while(k>0 && p1<v1.size())
                 {
                     if(p1==(int)v1.size()-1 && pr!=n)
                        break;
                     an *= v1[p1];
                     an %= mod;
                     p1++;
                     k--;
                 }
                 while(k>0 && p2<v2.size())
                 {
                     an *= (v2[p2]+mod)%mod;
                     an %= mod;
                     p2++;
                     k--;
                 }
             }

             cout<<an;

         }
         else
         {
             //cout<<v2.size()<<endl;
           int an = 1;
             int p1=0,p2=0;
             while(p1<(int)v1.size()-1 && p2<(int)v2.size()-1 && k>0)
             {
                 int pr1 = v1[p1]*v1[p1+1];
                 int pr2 = v2[p2]*v2[p2+1];
                 if(pr1>pr2)
                 {
                     an *= pr1%mod;
                     p1+=2;
                 }
                 else
                 {
                     an *= pr2%mod;
                     p2 += 2;
                 }
                 an %= mod;
                 k-=2;
             }
             if(k>0)
             {
                 //cout<<1<<endl;
                 while(k>0 && p1<v1.size())
                 {
                     if(p1==(int)v1.size()-1 && pr!=n)
                        break;
                     //cout<<p1<<endl;
                     an *= v1[p1];
                     an %= mod;
                     p1++;
                     k--;
                 }
                 while(k>0 && p2<v2.size())
                 {
                     an *= (v2[p2]+mod)%mod;
                     an %= mod;
                     p2++;
                     k--;
                 }
             }

             cout<<an;

         }

     }

  }


























  return 0;
}


Measured memory_bytes: 6732