#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const 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; }

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if (a.second != b.second) {
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

int main() {
    INIT;
    ll N, K;
    cin >> N >> K;
    vector<pair<ll, ll>> A;

    bool neg_flg = true;

    rep(i, N) {
        ll tmp;
        cin >> tmp;
        if (tmp >= 0) neg_flg = false;
        pair<ll, ll> p = make_pair(tmp, abs(tmp));
        A.pb(p);
    }

    sort(ALL(A), compare_by_b);

    mint ans = 1;
    if (neg_flg && K % 2 == 1) {
        for (ll i = N - 1; i >= N - K; i--) ans *= mint(A[i].first);
        cout << ans << endl;
        return 0;
    }

    ll cnt = 0;
    rep(i, K) if (A[i].first < 0) cnt++;

    bool is_zero = false;
    rep(i, K) {
        if (A[i].first == 0) is_zero = true;
    }

    if (cnt % 2 == 0 || is_zero || K == N) {
        rep(i, K) { ans *= mint(A[i].first); }
        cout << ans << endl;
        return 0;
    }

    ll p1 = INF, m1 = INF;
    rep(i, K) {
        if (A[i].first < 0) {
            m1 = A[i].first;
        } else {
            p1 = A[i].first;
        }
    }

    ll p2 = INF, m2 = INF;
    for (ll i = N - 1; i >= K; i--) {
        if (A[i].first < 0) {
            m2 = A[i].first;
        } else {
            p2 = A[i].first;
        }
    }

    rep(i, K) { ans *= mint(A[i].first); }

    if (p2 == INF) {
        ans = ans / mint(p1) * mint(m2);
    } else if (m2 == INF || p1 == INF) {
        ans = ans / mint(m1) * mint(p2);
    } else {
        if (p2 * p1 >= m2 * m1) {
            ans = ans / mint(m1) * mint(p2);
        } else {
            ans = ans / mint(p1) * mint(m2);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7440