#include <bits/stdc++.h>
#define inf (long long)(1e10)
using namespace std;

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

long long n, zero = 0, k;
vector<long long> pls, mns, v;

ModInt<> solve();

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    if (x > 0)
      pls.push_back(x);
    else if (x < 0)
      mns.push_back(x);
    else
      ++zero;
    v.push_back(x);
  }
  sort(pls.begin(), pls.end(), greater<long long>());
  sort(mns.begin(), mns.end());
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  auto f = [](long long l, long long r) { return abs(l) > abs(r); };
  sort(v.begin(), v.end(), f);
  long long num = inf, ev = 0, sum = 0, pm = inf, mm = inf;
  bool pch = 0, mch = 0;
  ModInt<> res = 1;
  if (n == k) {
    for (int i = 0; i < n; ++i) res *= v[i];
    return res;
  }
  for (int i = 0; i < k; ++i) {
    res *= v[i];
    if (v[i] > 0)
      pm = v[i];
    else if (v[i] < 0)
      mm = v[i], ev ^= 1;
  }
  if (!ev) return res;
  res /= mm;
  if (pm != inf) res /= pm;
  for (int i = k; i < n; ++i) {
    if (!pch && v[i] >= 0) {
      if (pm == inf)
        return res * v[i];
      else
        pm *= v[i], pch = 1;
    } else if (!mch && v[i] < 0) {
      mch = 1;
      mm *= v[i];
    }
  }
  if (pm == inf) {
    res = 1;
    for (int i = 0; i < k; ++i) res *= v[n - 1 - i];
    return res;
  }
  if (pch && mch)
    res *= max(mm, pm);
  else if (pch)
    res *= pm;
  else
    res *= mm;
  return res;
}


Measured memory_bytes: 7524