#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<ll, ll>;
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; }

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 istream& operator >> (istream &is, const Fp<mod>& x) noexcept {
        int val; is >> val;
        x = Fp<mod>(val);
        return is;
    }
    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 = 1e9+7;
using mint = Fp<mod>;
const ll inf = 1e18;

int main(){
    int n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    vector<ll> pos, neg;
    rep(i,n){
        if(a[i] < 0) neg.pb(a[i]);
        else pos.pb(a[i]);
    }

    int P = pos.size(), N = neg.size();
    bool is_pos = false;
    if(P > 0){
        if(n == k) is_pos = (N%2 == 0);
        else is_pos = true;
    }
    else{
        is_pos = (k%2 == 0);
    }

    mint ans = 1;
    if(!is_pos){
        sort(ALL(a), [](int l, int r){
            return abs(l) < abs(r);
        });
        rep(i,k) ans *= a[i];
    }
    else{
        sort(ALL(pos)); sort(RALL(neg));
        if(k % 2 == 1){
            ans *= pos.back();
            pos.pop_back();
        }
        vector<ll> v;
        while(pos.size() >= 2){
            ll x = pos.back(); pos.pop_back();
            x *= pos.back(); pos.pop_back();
            v.push_back(x);
        }
        while(neg.size() >= 2){
            ll x = neg.back(); neg.pop_back();
            x *= neg.back(); neg.pop_back();
            v.push_back(x);
        }
        sort(RALL(v));
        rep(i,k/2) ans *= v[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 8228