#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // using 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;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ld eps = 1e-5;

bool comp(ll a, ll b) { return abs(a) < abs(b); }

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

    ll n, k; cin>>n>>k;
    vl as(n); cin>>as;

    mint ans = 1;
    if (n == k) {
        rep(i, n) ans *= as[i];
        cout<<ans<<endl;
        return 0;
    }

    sort(rrng(as), comp);

    ll cnt = 0;
    rep(i, n) if (as[i] < 0) cnt++;
    if (cnt == n && k % 2) {
        rep(i, k) ans *= as[n - i - 1];
        cout<<ans<<endl;
        return 0;
    }

    ll mm = -LINF, mp = LINF;
    cnt = 0;
    rep(i, k) {
        ans *= as[i];
        if (as[i] < 0) {
            cnt++;
            chmax(mm, as[i]);
        }
        else chmin(mp, as[i]);
    }
    if (cnt % 2 == 0) {
        cout<<ans<<endl;
        return 0;
    }

    ll tp = -1, tm = 1;
    rrep(i, k, n) {
        if (as[i] >= 0) {
            tp = as[i];
            break;
        }
    }
    rrep(i, k, n) {
        if (as[i] < 0) {
            tm = as[i];
            break;
        }
    }
    if (tm == 1 || mp == LINF || abs(mp) * abs(tp) > abs(mm) * abs(tm)) {
        ans = ans / mm * tp;
        cout<<ans<<endl;
    }
    else {
        ans = ans / mp * tm;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4784