#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

template<typename T, long long MOD_VALUE>
class ModInt {
    static constexpr long long MOD = MOD_VALUE;
private:
    T value_;
public:
    ModInt() {}
    ModInt(const T& value) {if (value >= 0) {value_ = value % MOD;} else {T k = (MOD - 1 - value) / MOD; value_ = (value + k * MOD) % MOD;}}
    ModInt& operator+=(const ModInt& x)  {value_ += x.value_; if (value_ >= MOD) value_ -= MOD; return *this;}
    friend ModInt& operator+=(const T& x, const ModInt& y) {ModInt res(x); res.value_ += x.value_; if (res.value_ >= MOD) res.value_ -= MOD; return res;}
    ModInt& operator-=(const ModInt& x) {if (value_ < x.value_) value_ += MOD; value_ -= x.value_; return *this;}
    friend ModInt& operator-=(const T& x, const ModInt& y) {ModInt res(x); if (res.value_ < y.value_) res.value_ += MOD; res.value_ -= y.value_; return res;}
    ModInt& operator*=(const ModInt& x) {value_ = (value_ * x.value_) % MOD; return *this;}
    friend ModInt& operator*=(const T& x, const ModInt& y) {ModInt res(x); res.value_ = (res.value_ * y.value_) % MOD; return res;}
    const ModInt operator+(const ModInt& x) const {return ModInt(*this) += x;}
    friend const ModInt operator+(const T& x, const ModInt& y) {return ModInt(x) += y;}
    const ModInt operator-(const ModInt& x) const {return ModInt(*this) -= x;}
    friend const ModInt operator-(const T& x, const ModInt& y) {return ModInt(x) -= y;}
    const ModInt operator*(const ModInt& x) const {return ModInt(*this) *= x;}
    friend const ModInt operator*(const T& x, const ModInt& y) {return ModInt(x) *= y;}
    static ModInt modpow(ModInt x, long long y) {ModInt z = 1; while (y > 0) {if (y & 1) {z *= x;}x *= x; y /= 2;} return z;}
    ModInt& operator/=(const ModInt& x) {return *this *= modpow(x, MOD - 2);}
    const ModInt operator/(const ModInt& x) const {return ModInt(*this) /= x;}
    friend const ModInt operator/(const T& x, const ModInt& y) {return ModInt(x) /= y;}
    ModInt operator++(int) {ModInt tmp(*this); value_ = (value_ + 1 == MOD ? 0 : value_ + 1); return tmp;}
    ModInt operator--(int) {ModInt tmp(*this); value_ = (value_ - 1 < 0 ? MOD - 1 : value_ - 1); return tmp;}
    friend istream& operator>>(istream& stream, ModInt& x) {stream >> x.value_; x.value_ %= MOD; return stream;}
    friend ostream& operator<<(ostream& stream, const ModInt& x) {stream << x.value_; return stream;}
};

using mint = ModInt<ll, 1000000007>;

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    if (K == N) {
        mint ans = 1;
        rep(i, 0, N) {
            ans *= A[i];
        }
        cout << ans << endl;
        return 0;
    }
    int neg_cnt = 0;
    for (auto& a : A) {
        if (a < 0) {
            ++neg_cnt;
        }
    }
    if (neg_cnt == N) {
        sort(all(A));
        if (K % 2) {
            reverse(all(A));
        }
        mint ans = 1;
        rep(i, 0, K) {
            ans *= A[i];
        }
        cout << ans << endl;
        return 0;
    }
    if (neg_cnt == 0) {
        sort(all(A));
        reverse(all(A));
        mint ans = 1;
        rep(i, 0, K) {
            ans *= A[i];
        }
        cout << ans << endl;
        return 0;
    }
    mint ans = 1;
    sort(all(A), [](ll a, ll b) {
        if (llabs(a) == llabs(b)) {
            return a > b;
        } else {
            return llabs(a) > llabs(b);
        }
    });
    bool is_negative = false;
    rep(i, 0, K) {
        ans *= A[i];
        is_negative ^= A[i] < 0;
    }
    if (!is_negative) {
        cout << ans << endl;
        return 0;
    }
    ll min_pos = INF, max_pos = -1;
    ll min_neg = INF, max_neg = -1;
    rep(i, 0, K) {
        if (A[i] >= 0) {
            chmin(min_pos, A[i]);
        } else {
            chmin(min_neg, -A[i]);
        }
    }
    rep(i, K, N) {
        if (A[i] >= 0) {
            chmax(max_pos, A[i]);
        } else {
            chmax(max_neg, -A[i]);
        }
    }
    if (min_pos == INF) {
        ans /= -min_neg;
        ans *= max_pos;
    } else {
        if (max_neg < 0) {
            ans /= -min_neg;
            ans *= max_pos;
        } else if (max_pos < 0) {
            ans /= min_pos;
            ans *= -max_neg;
        } else {
            if (min_pos * max_pos < min_neg * max_neg) {
                ans /= min_pos;
                ans *= -max_neg;
            } else {
                ans /= -min_neg;
                ans *= max_pos;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4756