#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int const INF = 1001001001;

template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int n,k;
cin >> n >> k;

int zero = 0;
vl posi, nega, u;
rep(i,n) {
    int a;
    cin >> a;
    if(a > 0) {
        posi.push_back(a);
        u.push_back(a);
    }
    else if(a < 0) {
        nega.push_back(-a);
        u.push_back(-a);
    }
    else zero++;
}

int P = SZ(posi), N = SZ(nega);
bool positive_answer = false;
for(int i = 0; i <= k; i = i + 2) {
    if(N >= i && P >= k-i) positive_answer = true;
}

if(positive_answer) {
    if(k % 2 == 0) {
        sort(all(posi), greater<ll>());
        sort(all(nega), greater<ll>());
        priority_queue<ll> pq;

        rep(i, P/2) {
            pq.push(posi[2*i]*posi[2*i+1]);
        }
        rep(i, N/2) {
            pq.push(nega[2*i]*nega[2*i+1]);
        }
        mint res = 1;
        rep(i, k/2) {
            ll x = pq.top(); pq.pop();
            res *= x;
        }
        cout << res << endl;
    }
    if(k % 2 == 1) {
        sort(all(posi), greater<ll>());
        sort(all(nega), greater<ll>());
        priority_queue<ll> pq;
        rep(i, (P-1)/2) {
            pq.push(posi[2*i+1]*posi[2*i+2]);
        }
        rep(i, N/2) {
            pq.push(nega[2*i]*nega[2*i+1]);
        }
        mint res = posi[0];
        rep(i, k/2) {
            ll x = pq.top(); pq.pop();
            res *= x;
        }
        cout << res << endl;
    }
} else {
    if(zero > 0) cout << 0 << endl;
    else {
        sort(all(u));
        mint res = -1;
        rep(i,k) {
            res *= u[i];
        }
        cout << res << endl;
    }
}

return 0;
}

Measured memory_bytes: 8296