#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 
inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int power(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return power(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, power(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}
vector<int> fact,ifact;
void prep_fact(int mx = 1e6 + 40) {
  fact.assign(mx,0);
  ifact.assign(mx,0);
  fact[0] = 1;
  for (int i = 1; i < mx; ++i) fact[i] = mul(i, fact[i - 1]);
  ifact[mx - 1] = inv(fact[mx - 1]);
  for (int i = mx - 1; i > 0; --i) ifact[i - 1] = mul(i, ifact[i]);
}
inline int ncr(int n, int r) {
  if (n < r || r < 0 || n < 0) return 0;
  return mul(fact[n], mul(ifact[n - r], ifact[r]));
}
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k;
   cin >> n >> k;
   vector<int> a(n);
   int cnt = 0;
   f(i,0,n){
      cin >> a[i];
      cnt += (a[i] <= 0);
   }
   sort(all(a),[&](int u,int v){
      if(abs(u) == abs(v)){
         return u < v;
      }
      return abs(u) < abs(v);
   });

   if(n == k){
      int r = 1;
      f(i,0,n){
         r *= (a[i]+MOD)%MOD;
         r %= MOD;
      }
      return cout << r,0;
   }
   reverse(all(a));
   if(cnt == n){
      int r = 1;
      if(k & 1){
         reverse(all(a));
         f(i,0,k){
            r *= (a[i]+MOD)%MOD;
            r %= MOD;
         }
      }else{
         f(i,0,k){
            r *= (a[i]+MOD)%MOD;
            r %= MOD;
         }
      }
      return cout << r,0;
   }
   int pos = 0,c = 0,neg = 0;
   f(i,0,k){
      pos += (a[i] > 0);
      neg += (a[i] < 0);
      c |= (a[i] == 0);
   }
   if(c){
      return cout << 0,0;
   }
   if(neg & 1){
      if(pos){
         int r = 1;
         f(i,0,k){
            r *= (a[i]+MOD)%MOD;
            r %= MOD;
         }
         int neg = -1;
         int pos = -1;
         for(int i = k-1;i >= 0;i--){
            if(a[i] < 0 and neg == -1){
               neg = abs(a[i]);
            }
            if(a[i] > 0 and pos == -1){
               pos = abs(a[i]);
            }
         }
         int fneg = 0,fpos = 0;
         f(i,k,n){
            if(a[i] > 0 and fpos == 0){
               fpos = a[i];
            }
            if(a[i] < 0 and fneg == 0){
               fneg = abs(a[i]);
            }
         }
         if(pos*fpos > neg*fneg){
            r *= inv(MOD-neg);
            r %= MOD;
            r *= fpos;
            r %= MOD;
         }else{
            r *= inv(pos);
            r %= MOD;
            r *= (MOD-fneg);
            r %= MOD;
         }
         return cout << r,0;
      }else{
         int r = 1;
         f(i,0,k-1){
            r *= (a[i]+MOD)%MOD;
            r %= MOD;
         }
         f(i,k,n){
            if(a[i] >= 0){
               r *= a[i];
               r %= MOD;
               break;
            }
         }
         return cout << r,0;
      }
   }else{
      int r = 1;
      f(i,0,k){
         r *= (a[i]+MOD)%MOD;
         r %= MOD;
      }
      return cout << r,0;
   }
   return 0;
} 


Measured memory_bytes: 4784