#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
#define log loga
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int32_t MOD=MOD1;

vector<int> v[2];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
          int pos=0,neg=0,zero=0;
          int n,k;
          cin>>n>>k;
          int a[n];
          rep(i,0,n)
          {
                cin>>a[i];
                if(a[i]==0)zero++;
                else if(a[i]>0)
                {
                      pos++;
                      v[0].push_back(a[i]);
                }
                else
                {
                      neg++;
                      v[1].push_back(a[i]);
                }
          }
          
          rep(i,0,2)sort(v[i].rbegin(),v[i].rend());
          if(pos+neg<k){cout<<0<<endl;return 0;}
          else if(pos+neg==k)
          {
                if(neg%2==1 && zero!=0)
                {
                    cout<<0<<endl;return 0;
                }
                else
                {
                     int ans=1; 
                     rep(i,0,v[1].size())ans=(ans*(v[1][i]+MOD))%MOD;
                     rep(i,0,v[0].size())ans=(ans*v[0][i])%MOD;
                     cout<<ans<<endl;
                     return 0;         
                }
          }
          else if(pos==0)
          {
                if(zero==0)
                {
                      if(k%2==0)reverse(v[1].begin(),v[1].end());
                      if(1)
                      {
                          int mul=1;
                          rep(i,0,k)mul=(mul*(v[1][i]+MOD))%MOD;
                          cout<<mul<<endl;
                          return 0;            
                      }
                }
                else
                {
                      int siz=v[1].size();
                      if(k%2==1 || siz<k){cout<<0<<endl;return 0;}
                      reverse(v[1].begin(),v[1].end());
                      if(1)
                      {
                          int mul=1;
                          rep(i,0,k)mul=(mul*(v[1][i]+MOD))%MOD;
                          cout<<mul<<endl;
                          return 0;            
                      }
                }
          }
          else 
          {
               int siz1=v[0].size(),siz2=v[1].size();
               reverse(v[1].begin(),v[1].end());
               

               vector<pii> vals;
               for(auto it:v[0])vals.push_back({it,1});
               for(auto it:v[1])vals.push_back({-it,-1});

               sort(vals.rbegin(),vals.rend());

               int pos1=0,neg1=0;

               rep(i,0,k)
               {
                     if(vals[i].s==-1)neg1++;
               }  
               
              
               if(neg1%2==1)
               {
                     int ind1=-1,ind2=-1;
                     int val1=0,val2=0;
                     int toMul1=0,toMul2=0;
                     rev(i,k-1,0)
                     {
                          if(vals[i].s==1)
                          {
                                ind1=i;
                                break;
                          } 
                     }
                     rev(i,k-1,0)
                     {
                           if(vals[i].s==-1)
                           {
                                 ind2=i;
                                 break;
                           }
                     }
                     rep(i,k,vals.size())
                     {
                           if(ind1==-1)break;
                           if(vals[i].s==-1)
                           {
                                 toMul1=vals[i].f;
                                 break;
                           }  
                     }
                     rep(i,k,vals.size())
                     {
                           if(ind2==-1)break;
                           if(vals[i].s==1)
                           {
                                 toMul2=vals[i].f;
                                 break;
                           }
                     }

                     int mul=1;
                     int toRem=ind2;
                     if(ind1!=-1 && toMul1>0)
                     {
                           int temp=1;
                           if(ind2!=-1)temp*=vals[ind2].f;
                           mul=max(mul,temp*toMul1);
                     }
                     if(ind2!=-1 && toMul2>0)
                     {
                           int temp=1;
                           if(ind1!=-1)temp*=vals[ind1].f;
                           mul=max(mul,temp*toMul2);
                     }
                     mul%=MOD;
                     rep(i,0,k)
                     {
                            if(i==ind1 || i==ind2)continue;
                            mul=(mul*vals[i].f)%MOD;
                     }

                     cout<<mul<<endl;
                     return 0;
               }
               else
               {
                     int ans=1;
                     rep(i,0,k)ans=(ans*vals[i].f)%MOD;
                     cout<<ans<<endl;
                     return 0;
               }
               


          }

      }
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 11976