#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

template<int M>
struct ModInt {
public:
	using value_type = long long;
	
	ModInt(value_type val = 0) : val(val < 0 ? (M - (-val % M)) % M : val % M) {}
	
	explicit operator bool() const noexcept { return val; }
	bool operator ==(const ModInt & rhs) const noexcept { return val == rhs.val; }
	bool operator !=(const ModInt & rhs) const noexcept { return !(*this == rhs); }
	ModInt operator +() const noexcept { return ModInt(*this); }
	ModInt operator -() const noexcept { return ModInt(0) -= *this; }
	ModInt operator +(const ModInt & rhs) const noexcept { return ModInt(*this) += rhs; }
	ModInt operator -(const ModInt & rhs) const noexcept { return ModInt(*this) -= rhs; }
	ModInt operator *(const ModInt & rhs) const noexcept { return ModInt(*this) *= rhs; }
	ModInt operator /(const ModInt & rhs) const noexcept { return ModInt(*this) /= rhs; }
	
	ModInt & operator +=(const ModInt & rhs) noexcept {
		val += rhs.val;
		if (val >= M) val -= M;
		return *this;
	}
	ModInt & operator -=(const ModInt & rhs) noexcept {
		if (val < rhs.val) val += M;
		val -= rhs.val;
		return *this;
	}
	ModInt & operator *=(const ModInt & rhs) noexcept {
		val = val * rhs.val % M;
		return *this;
	}
	ModInt & operator /=(const ModInt & rhs) noexcept {
		*this *= rhs.inverse();
		return *this;
	}
	
	ModInt pow(value_type n) const {
		ModInt res = 1, x = val;
		if (n < 0) { x = x.inverse(); n = -n; }
		while (n) { if (n & 1) res *= x; x *= x; n >>= 1; }
		return res;
	}
	
	ModInt inverse() const {
		long long a = val, a1 = 1, a2 = 0, b = M, b1 = 0, b2 = 1;
		while (b > 0) {
			value_type q = a / b, r = a % b;
			value_type nb1 = a1 - q * b1, nb2 = a2 - q * b2;
			a = b; b = r;
			a1 = b1; b1 = nb1;
			a2 = b2; b2 = nb2;
		}
		assert(a == 1);
		return a1;
	}
	
	const value_type & get() const noexcept { return val; }
	static decltype(M) get_mod() noexcept { return M; }
	
	friend std::ostream & operator <<(std::ostream & os, const ModInt & rhs) { return os << rhs.val; }
	friend std::istream & operator >>(std::istream & is, ModInt & rhs) {
		value_type x;
		is >> x;
		rhs = ModInt(x);
		return is;
	}
private:
	value_type val;
};
using mint = ModInt<MOD>;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	
	vector<int> po, ne, ze;
	REP(i, N) {
		if (A[i] == 0) ze.emplace_back(A[i]);
		else if (A[i] < 0) ne.emplace_back(-A[i]);
		else po.emplace_back(A[i]);
	}
	sort(ALL(ne), greater<int>());
	sort(ALL(po), greater<int>());
	
	// maximize
	int ppo = 0, pne = 0, cnt = 0;
	while (ppo <= po.size() && pne <= ne.size() && cnt < K) {
		if (ppo < po.size() && pne < ne.size()) {
			if (po[ppo] < ne[pne]) {
				++pne; ++cnt;
				// 同じならどっちを取っても調整可能?
			}
			else {
				++ppo; ++cnt;
			}
		}
		else if (ppo < po.size()) {
			++ppo; ++cnt;
		}
		else {
			++pne; ++cnt;
		}
	}
	if (cnt < K) {
		cout << 0 << endl;
		return 0;
	}
	
	if (pne & 1) {
		// --po, ++ne
		// ++po, --ne
		if (ppo > 0 && pne < ne.size() || ppo < po.size() && pne > 0) {
			bool up = false;
			if (ppo > 0 && pne < ne.size() && ppo < po.size() && pne > 0)
				up = (ll)ne[pne - 1] * ne[pne] > (ll)po[ppo - 1] * po[ppo];
			else if (ppo > 0 && pne < ne.size())
				up = true;
			else
				up = false;
			
			if (up) { --ppo; ++pne; }
			else { ++ppo; --pne; }
			
			mint ans = 1;
			REP(i, ppo) ans *= po[i];
			REP(i, pne) ans *= ne[i];
			cout << ans << endl;
			return 0;
		}
		// ans -> negative
		if (!ze.empty()) {
			cout << 0 << endl;
			return 0;
		}
		
		// minimize
		ppo = 0, pne = 0, cnt = 0;
		reverse(ALL(po));
		reverse(ALL(ne));
		while (ppo <= po.size() && pne <= ne.size() && cnt < K) {
			if (ppo < po.size() && pne < ne.size()) {
				if (po[ppo] > ne[pne]) {
					++pne; ++cnt;
				}
				else {
					++ppo; ++cnt;
				}
			}
			else if (ppo < po.size()) {
				++ppo; ++cnt;
			}
			else {
				++pne; ++cnt;
			}
		}
		mint ans = 1;
		REP(i, ppo) ans *= po[i];
		REP(i, pne) ans *= ne[i];
		ans *= -1;
		cout << ans << endl;
		return 0;
	}
	else {
		mint ans = 1;
		REP(i, ppo) ans *= po[i];
		REP(i, pne) ans *= ne[i];
		cout << ans << endl;
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 5272