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

using ll = long long;

const long long MOD = 1000000007;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

void solve(ll N, ll K, std::vector<ll> A) {
  vector<ll> s, t;
  rep(i, N) {
    if (A.at(i) >= 0) {
      s.push_back(A.at(i));
    } else {
      t.push_back(A.at(i));
    }
  }

  int S = s.size();
  int T = t.size();

  bool ok = false;  // positive
  if (S > 0) {
    if (N == K) {
      ok = (T % 2 == 0);
    } else {  // N > K
      ok = true;
    }
  } else {  // S == 0
    ok = (K % 2 == 0);
  }

  mint ans = 1;
  if (!ok) {
    sort(all(A), [](int x, int y) { return abs(x) < abs(y); });
    rep(i, K) ans *= A.at(i);
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

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

    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back();
      s.pop_back();
      x *= s.back();
      s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back();
      t.pop_back();
      x *= t.back();
      t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i, K / 2) ans *= p.at(i);
  }

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 8264