#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <chrono>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

namespace Pred
{
  inline bool is_even(uint64_t n) { return (n & 1) == 0; }
  inline bool is_odd (uint64_t n) { return (n & 1) != 0; }

  const auto    LessInt64WithAbs = [](int64_t lhs, int64_t rhs){ return abs(lhs) < abs(rhs); };
  const auto GreaterInt64WithAbs = [](int64_t lhs, int64_t rhs){ return abs(lhs) > abs(rhs); };
};

using namespace std;

const uint64_t MOD = 1e+9 + 7;

template<typename T, T MOD = 1e+9 + 7>
class mod_int_base
{
protected:
  T _val;

public:
  mod_int_base(T val = 0) : _val(val % MOD) {}

  T get() const { return _val; }

  mod_int_base<T, MOD> pow(const T &e) const
  {
    if (e <= 1) {
      return (e == 0) ? mod_int_base<T, MOD>(1) : (*this);
    }

    mod_int_base<T, MOD> w = pow(e >> 1);
    mod_int_base<T, MOD> z = w * w;

    if (e % 2 == 1) { z *= (*this); }

    return z;
  }

  mod_int_base<T, MOD> operator=(const mod_int_base<T, MOD> &rhs) { _val = rhs.get(); return *this; }
  mod_int_base<T, MOD> operator=(const T &rhs)                    { _val = rhs % MOD; return *this; }

  mod_int_base<T, MOD> inv() const { return pow(MOD - 2); }

  bool operator==(const T &rhs) const { return _val == (rhs % MOD); }
  bool operator!=(const T &rhs) const { return _val != (rhs % MOD); }
  bool operator< (const T &rhs) const { return _val <  (rhs % MOD); }
  bool operator<=(const T &rhs) const { return _val <= (rhs % MOD); }
  bool operator> (const T &rhs) const { return _val >  (rhs % MOD); }
  bool operator>=(const T &rhs) const { return _val >= (rhs % MOD); }

  bool operator==(const mod_int_base<T, MOD> &rhs) const { return _val == rhs.get(); }
  bool operator!=(const mod_int_base<T, MOD> &rhs) const { return _val != rhs.get(); }
  bool operator< (const mod_int_base<T, MOD> &rhs) const { return _val <  rhs.get(); }
  bool operator<=(const mod_int_base<T, MOD> &rhs) const { return _val <= rhs.get(); }
  bool operator> (const mod_int_base<T, MOD> &rhs) const { return _val >  rhs.get(); }
  bool operator>=(const mod_int_base<T, MOD> &rhs) const { return _val >= rhs.get(); }

  mod_int_base<T, MOD> operator+(const T &rhs) const {
    return mod_int_base<T, MOD>((_val + (rhs % MOD)) % MOD);
  }
  mod_int_base<T, MOD> operator-(const T &rhs) const {
    return mod_int_base<T, MOD>((_val + (MOD - (rhs % MOD))) % MOD);
  }
  mod_int_base<T, MOD> operator*(const T &rhs) const {
    return mod_int_base<T, MOD>((_val * (rhs % MOD)) % MOD);
  }
  mod_int_base<T, MOD> operator/(const T &rhs) const {
    return mod_int_base<T, MOD>((_val * mod_int_base<T, MOD>(rhs).inv().get()) % MOD);
  }
  mod_int_base<T, MOD> operator+(const mod_int_base<T, MOD> &rhs) const {
    return mod_int_base<T, MOD>((_val + rhs.get()) % MOD);
  }
  mod_int_base<T, MOD> operator-(const mod_int_base<T, MOD> &rhs) const {
    return mod_int_base<T, MOD>((_val + (MOD - rhs.get())) % MOD);
  }
  mod_int_base<T, MOD> operator*(const mod_int_base<T, MOD> &rhs) const {
    return mod_int_base<T, MOD>((_val * rhs.get()) % MOD);
  }
  mod_int_base<T, MOD> operator/(const mod_int_base<T, MOD> &rhs) const {
    return mod_int_base<T, MOD>((_val * rhs.inv().get()) % MOD);
  }

  mod_int_base<T, MOD>& operator+=(const T &rhs) {
    _val = (_val + (rhs % MOD)) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator-=(const T &rhs) {
    _val = (_val + (MOD - (rhs % MOD))) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator*=(const T &rhs) {
    _val = (_val * (rhs % MOD)) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator/=(const T &rhs) {
    _val = (_val * mod_int_base<T, MOD>(rhs).inv().get()) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator+=(const mod_int_base<T, MOD> &rhs) {
    _val = (_val + rhs.get()) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator-=(const mod_int_base<T, MOD> &rhs) {
    _val = (_val + (MOD - rhs.get())) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator*=(const mod_int_base<T, MOD> &rhs) {
    _val = (_val * rhs.get()) % MOD;
    return *this;
  }
  mod_int_base<T, MOD>& operator/=(const mod_int_base<T, MOD> &rhs) {
    _val = (_val * rhs.inv().get()) % MOD;
    return *this;
  }
};

template<uint64_t MOD = 1e+9 + 7>
class mod_uint64_t_base : public mod_int_base<uint64_t, MOD>
{
public:
  mod_uint64_t_base(uint64_t n) : mod_int_base<uint64_t, MOD>(n) {}  
  operator uint64_t () const { return this->get(); }

  mod_uint64_t_base<MOD>& operator=(const mod_uint64_t_base<MOD> &rhs) { 
    this->_val = rhs.get();
    return *this;
  }
  mod_uint64_t_base<MOD>& operator=(const uint64_t &rhs) {
    this->_val = rhs % MOD;
    return *this;
  }

  mod_uint64_t_base<MOD> operator+(const int64_t &rhs) const {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    return mod_uint64_t_base<MOD>(this->_val + _rhs);
  }
  mod_uint64_t_base<MOD> operator-(const int64_t &rhs) const {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    return mod_uint64_t_base<MOD>((MOD + this->_val) - _rhs);
  }
  mod_uint64_t_base<MOD> operator*(const int64_t &rhs) const {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    return mod_uint64_t_base<MOD>(this->_val * _rhs);
  }

  mod_uint64_t_base<MOD>& operator=(const int64_t &rhs) {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    this->_val = _rhs;
    return *this;
  }
  mod_uint64_t_base<MOD>& operator+=(const int64_t &rhs) {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    this->_val = (this->_val + _rhs) % MOD;
    return *this;
  }
  mod_uint64_t_base<MOD>& operator-=(const int64_t &rhs) {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    this->_val = ((MOD + this->_val) - _rhs) % MOD;
    return *this;
  }
  mod_uint64_t_base<MOD>& operator*=(const int64_t &rhs) {
    uint64_t _rhs = static_cast<uint64_t>(MOD + rhs) % MOD;
    this->_val = (this->_val * _rhs) % MOD;
    return *this;
  }
};

typedef mod_uint64_t_base<MOD> m_uint64_t;

std::istream& operator>>(std::istream& is, m_uint64_t &v)
{
  uint64_t u;
  is >> u;
  v = m_uint64_t(u);
  return is;
}

std::ostream& operator<<(std::ostream& os, const m_uint64_t &v)
{
  os << v.get();
  return os;
}

int main()
{
  uint64_t N, K;
  cin >> N >> K;

  vector<int64_t> A(N);
  cin >> A;

  uint64_t M = 0, P = 0;
  N_TIMES(n, N) { if (A[n] >= 0) { ++P; } else { ++M; } }

  m_uint64_t T = 1;
  if (K == N) { // 選択肢がないとき
    N_TIMES(k, K) { T *= A[k]; }
  } else if (((K % 2) == 1) && (P == 0)) { // 必ず負になる
    sort(A.begin(), A.end(), Pred::LessInt64WithAbs);

    N_TIMES(k, K) { T *= A[k]; }
  } else {
    sort(A.begin(), A.end(), Pred::GreaterInt64WithAbs);

    deque<int64_t> pos_a, pos_b, neg_a, neg_b;
    uint64_t count_neg = 0, k = 0;
    N_TIMES(n, N) {
      if (k < K) {
        if (A[n] >= 0) {
          pos_a.push_back(A[n]);
        } else {
          neg_a.push_back(A[n]);
          ++count_neg;
        }
        ++k;
      } else {
        if (A[n] >= 0) {
          pos_b.push_back(A[n]);
        } else {
          neg_b.push_back(A[n]);
        }
      }
    }

    if (Pred::is_odd(count_neg)) { // 負になった
      if (pos_a.empty() || neg_b.empty()) {
        neg_a.pop_back();
        pos_a.push_back( pos_b.front() );
        pos_b.pop_front();
      } else if (neg_a.empty() || pos_b.empty()) {
        pos_a.pop_back();
        neg_a.push_back( neg_b.front() );
        neg_b.pop_front();
      } else {
        uint64_t p = abs(pos_b.front()) * abs(pos_a.back());
        uint64_t q = abs(neg_b.front()) * abs(neg_a.back());
        if (p > q) {
          neg_a.pop_back();
          pos_a.push_back( pos_b.front() );
          pos_b.pop_front();
        } else {
          pos_a.pop_back();
          neg_a.push_back( neg_b.front() );
          neg_b.pop_front();
        }
      }
    }

    while (!pos_a.empty()) { T = T * pos_a.front(); pos_a.pop_front(); }
    while (!neg_a.empty()) { T = T * neg_a.front(); neg_a.pop_front(); }
  }
  cout << (T % MOD) << endl;

  return 0;
}

Measured memory_bytes: 6300