#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long 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(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    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 operator==(const mint& a, const mint& b) { return a.x == b.x;}

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> plus, minus;
    rep(i, n) {
        if (a[i] > 0) {
            plus.push_back(a[i]);
        } else if (a[i] < 0) {
            minus.push_back(-a[i]);
        }
    }
    
    int nonzero = sz(plus) + sz(minus);
    if (nonzero < k) {
        cout << 0 << endl;
        return 0;
    }
    
    if (k % 2 == 1) {
        if (sz(plus) == 0 || (nonzero == k && sz(plus) % 2 == 0)) {
            if (nonzero == n) {
                sort(all(minus));
                mint ans = 1;
                rep(i, k) {
                    ans *= -minus[i];
                }
                cout << ans << endl;
                return 0;
            } else {
                cout << 0 << endl;
                return 0;
            }
        }
    } else {
        if (nonzero == k && sz(minus) % 2 == 1) {
            if (nonzero == n) {
                mint ans = 1;
                rep(i, n) ans *= a[i];
                cout << ans << endl;
                return 0;
            } else {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    
    int k_plus = k;
    int k_minus = 0;
    if (sz(plus) < k) {
        if ((k - sz(plus)) % 2 == 1) {
            k_plus = sz(plus) - 1;
            k_minus = k - sz(plus) + 1;
        } else {
            k_plus = sz(plus);
            k_minus = k - sz(plus);
        }
    }
    
    sort(rall(plus));
    sort(rall(minus));
    int mx_k_plus = k_plus;
    mp::cpp_int delta = 0;
    mp::cpp_int mx = 0;
    while (k_minus + 2 <= sz(minus) && k_plus - 2 >= 0) {
        ll plus1 = plus[k_plus-1], plus2 = plus[k_plus-2];
        ll minus1 = minus[k_minus], minus2 = minus[k_minus+1];
        delta += minus1 * minus2 - plus1 * plus2;
        if (mx < delta) {
            mx_k_plus = k_plus - 2;
            mx = delta;
        }
        k_minus += 2;
        k_plus -= 2;
    }

    mint ans = 1;
    rep(i, mx_k_plus) ans *= plus[i];
    rep(i, k - mx_k_plus) ans *= minus[i];
    cout << ans << endl;
}


Measured memory_bytes: 5152