#include <bits/stdc++.h>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

/**
 * @title Modint
 * @docs mint.md
 */
template <uint32_t M> class ModInt{
public:
  constexpr static uint32_t MOD = M;
  uint64_t val;
  
  constexpr ModInt(): val(0){}
  constexpr ModInt(int64_t n){
    if(n >= M) val = n % M;
    else if(n < 0) val = n % M + M;
    else val = n;
  }
  
  inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);}
  inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);}
  inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);}
  inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);}
  
  inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;}
  inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;}
  inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;}
  inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;}
  inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;}
  
  inline constexpr bool operator==(const ModInt &a) const {return val == a.val;}
  inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;}
  
  inline constexpr auto& operator++(){*this += 1; return *this;}
  inline constexpr auto& operator--(){*this -= 1; return *this;}
  
  inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;}
  inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;}
  
  inline constexpr static ModInt power(int64_t n, int64_t p){
    if(p < 0) return power(n, -p).inv();
    
    int64_t ret = 1, e = n % M;
    for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M;
    return ret;
  }
  
  inline constexpr static ModInt inv(int64_t a){
    int64_t b = M, u = 1, v = 0;
    
    while(b){
      int64_t t = a / b;
      a -= t * b; std::swap(a,b);
      u -= t * v; std::swap(u,v);
    }
    
    u %= M;
    if(u < 0) u += M;
    
    return u;
  }
  
  inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);}
  
  inline constexpr auto power(int64_t p) const {return power(val, p);}
  inline constexpr auto inv() const {return inv(val);}
  
  friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);}
  
  friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;}
  friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;}
  friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;}
  friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;}
  
  friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;}
  friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;}

  template <int N>
  inline static auto div(){
    static auto value = inv(N);
    return value;
  }

  explicit operator int32_t() const noexcept {return val;}
  explicit operator int64_t() const noexcept {return val;}
};

using mint = ModInt<1000000007>;

int main(){
  int N, K;

  while(std::cin >> N >> K){
    std::vector<int64_t> A(N);
    for(int i = 0; i < N; ++i) std::cin >> A[i];

    mint ans = 1;

    if(N == K){
      for(auto x : A) ans *= x;
    }else{
      if(std::all_of(A.begin(), A.end(), [](auto x){return x <= 0;})){
        if(K % 2 == 0){
          std::sort(A.begin(), A.end());
          for(int i = 0; i < K; ++i) ans *= A[i];
        }else{
          std::sort(A.rbegin(), A.rend());
          for(int i = 0; i < K; ++i) ans *= A[i];
        }
      }else{
        int zero = std::count(A.begin(), A.end(), 0);
        if(zero > N - K){
          ans = 0;
        }else{
          N -= zero;

          if(N == K){
            for(auto x : A) if(x != 0) ans *= x;
          }else{
            std::vector<int64_t> pos, neg;
            for(auto x : A){
              if(x > 0) pos.push_back(x);
              if(x < 0) neg.push_back(x);
            }

            std::sort(pos.begin(), pos.end());
            std::sort(neg.rbegin(), neg.rend());
            
            //            dump(pos, neg);

            std::vector<int64_t> temp;

            if(K % 2 == 1){
              ans *= pos.back();
              pos.pop_back();
            }

            while(pos.size() >= 2){
              int64_t t = pos.back(); pos.pop_back();
              t *= pos.back(); pos.pop_back();
              temp.push_back(t);
            }

            while(neg.size() >= 2){
              int64_t t = neg.back(); neg.pop_back();
              t *= neg.back(); neg.pop_back();
              temp.push_back(t);
            }

            std::sort(temp.rbegin(), temp.rend());

            for(int i = 0; i < K / 2; ++i){
              ans *= temp[i];
            }
          }
        }
      }
    }

  
    std::cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 8160