// E - Multiplication 4

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//const int INF = 2147483647;
const ll INF = 9223372036854775807;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct ModInt {
	long long val;
	constexpr ModInt(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr ModInt operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr ModInt operator + (const ModInt& r) const noexcept { return ModInt(*this) += r; }
	constexpr ModInt operator - (const ModInt& r) const noexcept { return ModInt(*this) -= r; }
	constexpr ModInt operator * (const ModInt& r) const noexcept { return ModInt(*this) *= r; }
	constexpr ModInt operator / (const ModInt& r) const noexcept { return ModInt(*this) /= r; }
	constexpr ModInt& operator += (const ModInt& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr ModInt& operator -= (const ModInt& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr ModInt& operator *= (const ModInt& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr ModInt& operator /= (const ModInt& 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 ModInt& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const ModInt& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream &os, const ModInt<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr ModInt<MOD> modpow(const ModInt<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 ll MOD = 1000000007;
using mint = ModInt<MOD>;

ll N, K;
pair<ll, ll> A[200000];

mint solve_ans_positive() {
	mint result = 1;
	sort(A, A+N);
	reverse(A, A+N);

	bool result_positive = true;
	ll min_abs_positive = 0;
	ll min_abs_negative = 0;
	for (int i=0; i<K; i++) {
		ll a = A[i].second;
		result *= a;
		if (a > 0) min_abs_positive = a;
		if (a < 0) min_abs_negative = a;
		if (a < 0) result_positive ^= 1;
		if (a == 0) return (mint)0;
	}

	if (result_positive) return result;

	// 以下、このままでは負なので正になるように調整

	ll remain_max_abs_positive = 0;
	ll remain_max_abs_negative = 0;
	for (int i=K; i<N; i++) {
		ll a = A[i].second;
		if (a > remain_max_abs_positive) remain_max_abs_positive = a;
		if (a < remain_max_abs_negative) remain_max_abs_negative = a;
	}

	if (min_abs_positive == 0) {
		result = result * remain_max_abs_positive / min_abs_negative;
	} else if (remain_max_abs_negative * min_abs_negative > remain_max_abs_positive * min_abs_positive) {
		result = result * remain_max_abs_negative / min_abs_positive;
	} else {
		result = result * remain_max_abs_positive / min_abs_negative;
	}

	return result;
}

mint solve_greedly() {
	mint result = 1;
	sort(A, A+N);

	for (int i=0; i<K; i++) {
		result *= A[i].second;
	}

	return result;
}

int main() {
	cin >> N >> K;

	ll a;
	for (int i=0; i<N; i++) {
		cin >> a;
		A[i] = make_pair(abs(a), a);
	}

	if (K == N) {
		mint ans = solve_greedly();
		cout << ans << endl;
		return 0;
	}

	bool all_negative = true;

	for (int i=0; i<N; i++) {
		if (A[i].second >= 0) all_negative = false;
	}

	bool ans_positive;
	if (all_negative && (K % 2 == 1)) {
		ans_positive = false;
	} else {
		ans_positive = true;
	}

	mint ans;
	if (ans_positive) ans = solve_ans_positive();
	else ans = solve_greedly();

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6644