#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>
#include <thread>
#include <chrono>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;


using namespace std;
template<int64_t M = 1000000007>
class ModInt {
public:
	ModInt() : val_(0) {};

	ModInt(int64_t val) {
		this->val_ = val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0)  this->val_ += M;
	}

	operator int64_t() const {
		return this->val_;
	}

	ModInt& operator += (int64_t val) {
		this->val_ += val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator -= (int64_t val) {
		this->val_ -= val;
		this->val_ %= M;
		while (this->val_ >= M) this->val_ -= M;
		while (this->val_ < 0) this->val_ += M;

		return *this;
	}

	ModInt& operator *= (int64_t val) {
		this->val_ *= val;
		this->val_ %= M;

		return *this;
	}

	ModInt& operator /= (int64_t val) {
		ModInt v = ModInt::pow(val, M - 2);
		*this *= v;

		return *this;
	}

	ModInt operator + (int64_t v) const {
		ModInt ret = *this;
		return (ret += v);
	}

	ModInt operator - (int64_t v) const {
		ModInt ret = *this;
		return (ret -= v);
	}

	ModInt operator * (int64_t v) const {
		ModInt ret = *this;
		return (ret *= v);
	}

	ModInt operator / (int64_t v) const {
		ModInt ret = *this;
		return (ret /= v);
	}

	static ModInt pow(ModInt n, int64_t m) {
		if (m == 0) {
			ModInt ret(1);
			return ret;
		}
		if (m == 1) {
			return n;
		}

		ModInt v = pow(n, m / 2);
		ModInt ret = v * v;
		if (m & 1) {
			ret *= n;
		}
		return ret;
	}

	ostream& operator << (ostream& out) {
		out << this->val_;
		return out;
	}

private:
	int64_t val_;
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, k; cin >> n >> k;

	vector<int64_t> as(n);

	bool all_minus = true;
	FOR_LT(i, 0, n) {
		cin >> as[i];
		if (as[i] >= 0) all_minus = false;
	}

	if (all_minus && (k & 1)) {
		sort(as.begin(), as.end(), [](const int64_t lhs, const int64_t rhs) {
			return abs(lhs) < abs(rhs);
		});
		ModInt<> ans(1);
		FOR_LT(i, 0, k) {
			ans *= abs(as[i]);
		}
		cout << ModInt<>(0) - ans << endl;
		return 0;
	}

	sort(as.begin(), as.end(), [](const int64_t lhs, const int64_t rhs) {
		return abs(lhs) > abs(rhs);
		});

	int cm = 0;
	FOR_LT(i, 0, k) {
		if (as[i] < 0) cm++;
	}
	if (as[k - 1] == 0) {
		cout << 0 << endl;
		return 0;
	}

	ModInt<> ans(1);
	FOR_LT(i, 0, k) {
		ans *= abs(as[i]);
	}
	if ((cm & 1) == 0) {
		cout << ans << endl;
		return 0;
	}

	int lidx = -1, ridx = -1;
	FOR_DW(i, k - 1, 0) {
		if (as[i] < 0) {
			lidx = i;
			break;
		}
	}
	FOR_LT(i, k, n) {
		if (as[i] >= 0) {
			ridx = i;
			break;
		}
	}

	int l2idx = -1, r2idx = -1;
	FOR_DW(i, k - 1, 0) {
		if (as[i] > 0) {
			l2idx = i;
			break;
		}
	}
	FOR_LT(i, k, n) {
		if (as[i] <= 0) {
			r2idx = i;
			break;
		}
	}

	//cout << lidx << " " << ridx << " " << l2idx << r2idx << endl;
	if ((lidx == -1 || ridx == -1) && (l2idx == -1 || r2idx == -1)) {
		cout << ModInt<>(0) -ans << endl;
		return 0;
	}

	if (lidx == -1 || ridx == -1) {
		ans /= abs(as[l2idx]);
		ans *= abs(as[r2idx]);
		cout << ans << endl;
		return 0;
	}
	if (l2idx == -1 || r2idx == -1) {
		ans /= abs(as[lidx]);
		ans *= abs(as[ridx]);
		cout << ans << endl;
		return 0;
	}

	uint64_t d1 = abs(as[lidx]);
	uint64_t d2 = abs(as[l2idx]);
	uint64_t m1 = abs(as[ridx]);
	uint64_t m2 = abs(as[r2idx]);

	if (m1 * d2 >= m2 * d1) {
		ans /= d1;
		ans *= m1;
	}
	else {
		ans /= d2;
		ans *= m2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4796