#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
	ll x;
	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 {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=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.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

ll solve2(vll& a) {
    ll n = a.size();
    mint ans = 1;
    for(ll i = 0; i < n; i++) ans *= a[i];
    return ans.x;
}

ll solve3(vll& a, ll k) {
    ll n = a.size();
    sort(a.begin(), a.end(), greater<ll>());
    mint ans = 1;
    a.erase(a.begin() + k, a.end());
    return solve2(a);
}

ll solve() {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    bool minus = true;
    rep(i, n) {
        cin >> a[i];
        if(a[i] >= 0) minus = false;
    }
    if(n == k) return solve2(a);
    else if(minus && k % 2) return solve3(a, k);
    vll pv, mv;
    for(ll i = 0; i < n; i++) {
        if(a[i] >= 0) pv.push_back(a[i]);
        else mv.push_back(a[i]);
    }
    ll pn = pv.size();
    ll mn = mv.size();
    if(pn > 0) sort(pv.begin(), pv.end(), greater<ll>());
    if(mn > 0) sort(mv.begin(), mv.end());
    ll pi = 0, mi = 0;
    mint ans = 1;
    while(pi + mi < k) {
        if(pn - pi >= 2 && mn - mi >= 2 && k - pi - mi >= 2) {
            if(pv[pi] * pv[pi + 1] > mv[mi] * mv[mi + 1]) {
                ans *= pv[pi++];
            }
            else {
                ans *= mv[mi++];
                ans *= mv[mi++];
            }
        }
        else if(pn - pi <= 1 && mn - mi >= 2 && k - pi - mi >= 2) {
            ans *= mv[mi++];
            ans *= mv[mi++];
        }
        else {
            ans *= pv[pi++];
        }
    }
    return ans.x;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cout << solve() << endl;
}

Measured memory_bytes: 6808