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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : 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 -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, 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);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    for (auto &i : A) cin >> i;

    sort(A.begin(), A.end(), [](int a, int b){return abs(a) > abs(b);});

    rep(i, K) {
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (K == N) {
        mint ans = 1;
        rep(i, K) ans *= A[i];
        cout << ans << endl;
        return 0;
    }

    bool minus = false;
    rep(i, K) {
        if (A[i] < 0) minus = !minus;
    }

    if (!minus) {
        mint ans = 1;
        rep(i, K) ans *= A[i];
        cout << ans << endl;
        return 0;
    }

    bool hasPlus = false;
    for (auto &i : A) {
        if (0 < i) hasPlus = true;
    }

    if (!hasPlus) {
        mint ans = 1;
        rep(i, K) ans *= A[N-1-i];
        cout << ans << endl;
        return 0;
    }

    int idx_of_p = -1, idx_of_n = -1;
    repr(i, K) {
        if (0 < A[i]) {
            idx_of_p = i;
            break;
        }
    }
    repr(i, K) {
        if (A[i] < 0) {
            idx_of_n = i;
            break;
        }
    }

    mint ans = 1;
    rep(i, K) {
        if (i == idx_of_p || i == idx_of_n) continue;
        ans *= A[i];
    }

    ll res_of_p = -INF;
    if (idx_of_p != -1) {
        for (int i = K; i < N; ++i) {
            if (0 <= A[i]) {
                res_of_p = (ll)A[idx_of_p] * A[i];
                break;
            }
        }
    } else {
        for (int i = K; i < N; ++i) {
            if (0 <= A[i]) {
                ans *= A[i];
                break;
            }
        }
        cout << ans << endl;
        return 0;
    }

    ll res_of_n = -INF;
    if (idx_of_n != -1) {
        for (int i = K; i < N; ++i) {
            if (A[i] <= 0) {
                res_of_n = (ll)A[idx_of_n] * A[i];
                break;
            }
        }
    }

    ll res = -INF;
    if (res_of_p != -INF) chmax(res, res_of_p);
    if (res_of_n != -INF) chmax(res, res_of_n);
    ans *= res;
    cout << ans << endl;
}


Measured memory_bytes: 3964