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

constexpr int NF = numeric_limits<int>::min() + 1;

template<int32_t Mod>
class ModInt {
public:
  using ModType = decltype(Mod);
  static constexpr int m = Mod;
 
  template<typename T> ModType mod(T n) const {
    if(n < 0 || n >= m) n %= m;
    if(n < 0) n += m;
    return static_cast<ModType>(n);
  } 
  template<typename T> ModInt pow(T p) const {
    ModInt res(1), a(*this);
    do {
      if(p & 1) res *= a;
      a *= a;
    } while(p >>= 1);
    return res;
  }
  ModInt inv() const {
    return pow(m - 2);
  }
 
  ModInt() = default;
  ModInt(const ModInt& other): val(other.val) {}
  template<typename T> ModInt(T n): val(mod(n)) {}
  ModInt& operator=(const ModInt& other) { val = other.val; return *this; }
 
  ModInt& operator+=(const ModInt& other) {
    if((val += other.val) >= m) val -= m; return *this; }
  ModInt& operator-=(const ModInt& other) {
    if((val -= other.val) < 0) val += m; return *this; }
  ModInt& operator*=(const ModInt& other) {
    val = mod((int64_t) (val) * (int64_t)(other.val)); return *this; }
  ModInt& operator/=(const ModInt& other) { return *this *= other.inv(); }
 
  ModInt& operator++() { return *this += 1; }
  ModInt& operator--() { return *this -= 1; }
  ModInt operator++(int) { ModInt ret(*this); *this += 1; return ret; }
  ModInt operator--(int) { ModInt ret(*this); *this -= 1; return ret; }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { return ModInt(m - val); }
 
  ModInt operator+(const ModInt& other) const { return ModInt(*this) += other; }
  ModInt operator-(const ModInt& other) const { return ModInt(*this) -= other; }
  ModInt operator*(const ModInt& other) const { return ModInt(*this) *= other; }
  ModInt operator/(const ModInt& other) const { return ModInt(*this) /= other; }
 
  template<typename T> ModInt operator+(T other) const { return *this + ModInt(other); }
  template<typename T> ModInt operator-(T other) const { return *this - ModInt(other); }
  template<typename T> ModInt operator*(T other) const { return *this * ModInt(other); }
  template<typename T> ModInt operator/(T other) const { return *this / ModInt(other); }
  template<typename T> ModInt& operator+=(T other) { return *this += ModInt(other); }
  template<typename T> ModInt& operator-=(T other) { return *this -= ModInt(other); }
  template<typename T> ModInt& operator*=(T other) { return *this *= ModInt(other); }
  template<typename T> ModInt& operator/=(T other) { return *this /= ModInt(other); }
 
  template<typename T> friend
    ModInt operator+(T lhs, const ModInt& rhs) { return rhs + lhs; }
  template<typename T> friend
    ModInt operator-(T lhs, const ModInt& rhs) { return -rhs + lhs; }
  template<typename T> friend
    ModInt operator*(T lhs, const ModInt& rhs) { return rhs * lhs; }
  template<typename T> friend
    ModInt operator/(T lhs, const ModInt& rhs) { return ModInt(lhs) / rhs; }
 
  friend ostream& operator<<(ostream& os, const ModInt& m) { return (os << m.val); }
  friend istream& operator>>(istream& is, const ModInt& m) {
    int64_t n; is >> n; m.val = mod(n); return is; }
 
  explicit operator ModType() { return val; }
private:
  ModType val = 0;
};
using Mint = ModInt<1000000000 + 7>;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), [](auto x, auto y) {return abs(x) > abs(y);});
  int s = 0;
  bool seen_0 = false;
  for(int i = 0; i < k; ++i) {
    s ^= a[i] < 0;
    if(a[i] == 0) {
      seen_0 = true;
    }
  }
  if(seen_0) {
    cout << 0 << '\n';
    return 0;
  }
  Mint ans = 1;
  for(int i = 0; i < k; ++i) {
    ans *= a[i];
  }

  if(s == 0) {
    cout << ans << '\n';
    return 0;
  }

  int pos = NF, neg = NF;
  for(int i = 0; i < k; ++i) {
    if(a[i] > 0) pos = a[i];
    if(a[i] < 0) neg = a[i];
  }
  int ppos = NF, nneg = NF;
  for(int i = n - 1; i >= k; --i) {
    if(a[i] > 0) ppos = a[i];
    if(a[i] < 0) nneg = a[i];
  }
  if(!(pos != NF && nneg != NF) && !(neg != NF && ppos != NF)) {
    ans = 1;
    for(int i = n - 1; i > n - 1 - k; --i) {
      ans *= a[i]; 
    }
    cout << ans << '\n';
    return 0;
  }
  int num, denum;
  if(pos != NF && nneg != NF) num = nneg, denum = pos;
  else num = ppos, denum = neg;
  if(pos != NF && nneg != NF && ppos != NF && neg != NF) {
    if(1LL * nneg * neg > 1LL * pos * ppos) {
      tie(num, denum) = make_pair(nneg, pos);
    } else {
      tie(num, denum) = make_pair(ppos, neg);
    }
  }
  ans /= denum;
  ans *= num;
  cout << ans << '\n';
}

Measured memory_bytes: 3968