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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

// 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, const mint &a) {
  return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
  return os << a.x;
}

template <typename T>
int sgn(T val) {
  return (T(0) < val) - (val < T(0));
}

void solve(long long N, long long K, std::vector<long long> A) {
  bool all_minus = true;
  REP(i, N) {
    if (A[i] >= 0) {
      all_minus = false;
      break;
    }
  }
  if (N == K) {
    mint ans = 1;
    ll sign = 1;
    REP(i, N) {
      ans *= mint(abs(A[i]));
      sign *= sgn(A[i]);
    }
    if (sign == -1) {
      ans = -ans;
    }
    cout << ans << endl;
  } else if (K % 2 == 1 && all_minus) {
    sort(ALL(A), greater<ll>());
    mint ans = 1;
    REP(i, K) {
      ans *= mint(abs(A[i]));
    }
    cout << -ans << endl;
  } else {
    sort(ALL(A), greater<ll>());
    deque<ll> p;
    vector<ll> m;
    REP(i, N) {
      if (A[i] >= 0) {
        p.push_back(A[i]);
      } else {
        m.push_back(-A[i]);
      }
    }
    reverse(ALL(m));
    mint ans = 1;
    if (K % 2 == 1) {
      ans *= mint(p[0]);
      p.pop_front();
      K--;
    }
    vector<ll> d;
    REP(i, p.size() / 2) {
      d.push_back(p[2 * i] * p[2 * i + 1]);
    }
    REP(i, m.size() / 2) {
      d.push_back(m[2 * i] * m[2 * i + 1]);
    }
    sort(ALL(d), greater<ll>());
    REP(i, K / 2) {
      ans *= mint(d[i]);
    }
    cout << ans << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 8192