#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
#define fs  first  
#define sc  second
#define ARR array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>


#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;

#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
}

// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif

typedef long long ll;  
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);} 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  while (!isdigit(ch) && ch!=EOF) minus = (ch == '-'? -1 : minus),ch= (char) getchar_unlocked();

  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char *x) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();

  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
inline void WRITE_STRING(string &x) {
  for(char c: x) 
    putchar_unlocked(c);
}
const ll OOl = 1e18 ;
const int N = 1e6+1,OO = 1e9,OOm = 0x3f3f3f3f, MOD = 1e9 + 7;
int arr[N];
ll add(ll a)
{
  a+=MOD;
  if(a>=MOD) a-=MOD;
  return a;
}
ll mul(ll a,int b)
{
  return (a*b)%MOD;
}
bool compare(int a,int b)
{
  return abs(a)>abs(b);
}

int main()
{
  int n,k;
  READn(n),READn(k);
  bool pos = 0;
  for(int i=0;i<n;++i)
  {
    READn(arr[i]);
    if(arr[i]>0) pos=1;
  }
  
  ll prod = 1;
  if(!pos) 
  {
    sort(arr,arr+n,compare);
    for(int i=0;i<k;++i) prod = mul(prod,k&1?arr[n-i-1]:arr[i]);
  }
  else
  {
   sort(arr,arr+n,greater<int>());
   int l =0,r=n-1;
   while(k)
   {
     if(k&1) prod = mul(prod,arr[l++]),k--;
     else
     {
       if(1ll*arr[l]*arr[l+1]>=1ll*arr[r]*arr[r-1])
       {
         prod = mul(prod,arr[l]);
         prod = mul(prod,arr[l+1]);
         l+=2;
       }
       else
       {
         prod = mul(prod,arr[r]);
         prod = mul(prod,arr[r-1]);
         r-=2;
       }
       k-=2;
     }
   }
  }
  
  WRITEn(add(prod));
  return 0;
}



Measured memory_bytes: 4308