#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;


#include <vector>
#define debug(x) print(x, #x)
#define debug_1d(arr, len) print(arr, len, #arr)
#define debug_2d(arr, row, col) print((decltype(&arr[0][0]))arr, row, col, sizeof(*arr)/sizeof(**arr), #arr)
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a1,a2,a3,x,...) x
#define deb(...) CHOOSE((__VA_ARGS__,debug_2d,debug_1d,debug,~))(__VA_ARGS__)
template<typename T> void print(T x, string tag="") {
	if (tag.empty()) cout << x << endl;
	else cout << tag << ": " << x << endl;
}
template<typename T> void print(T *ar, int len, string tag="") {
	if (!tag.empty()) cout << tag << ": ";
	for (int i = 0; i < len; ++i) cout << ar[i] << ' ';
		cout << endl;
}
template<typename T> void print(T *ar, int row, int col, int C, string tag="") {
	if (!tag.empty()) cout << tag << ": " << endl;
	for (int i = 0; i < row; ++i) {
		for (int j = 0; j < col; ++j) {
			cout << ar[i*C + j] << ' ';
		}
		cout << endl;
	}
}
template<typename T> void print(vector<T> v, string tag="") {
	if (!tag.empty()) cout << tag << ": ";
	for (int e : v) cout << e << ' ';
	cout << endl;
}
template<typename T> void print(vector<vector<T>> v, string tag="") {
	if (!tag.empty()) cout << tag << ": " << endl;
	for (auto ev : v) {
		for (auto e : ev) cout << e << ' ';
		cout << endl;
	}
}

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> A(n);
	bool all_plus = true, all_minus = true;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		if (A[i] < 0) all_plus = false;
		if (A[i] > 0) all_minus = false;
	}
	if (n == k) {
		long long ans = 1;
		for (long long e : A) {
			ans = mod(ans * e);
		}
		cout << ans << endl;
		return 0;
	}
	if (all_plus) {
		sort(A.begin(), A.end(), greater<long long>());
		long long ans = 1;
		for (int i = 0; i < k; i++) {
			ans = mod(ans * A[i]);
		}
		cout << ans << endl;
		return 0;
	}
	if (all_minus) {
		if (k & 1) sort(A.begin(), A.end(), greater<long long>());
		else sort(A.begin(), A.end());
		long long ans = 1;
		for (int i = 0; i < k; i++) {
			ans = mod(ans * A[i]);
		}
		cout << ans << endl;
		return 0;
	}
	vector<long long> p, m;
	for (long long e : A) {
		if (e >= 0) p.push_back(e);
		else m.push_back(-e);
	}
	sort(p.begin(), p.end(), greater<long long>());
	sort(m.begin(), m.end(), greater<long long>());
	if (m.size() % 2 == 1) m.pop_back();
	vector<long long> m2(m.size()/2, 1);
	for (int i = 0; i < m.size(); i++) {
		m2[i/2] *= m[i];
	}
	vector<long long> ap, am;
	int i = 0, j = 0;
	if (k & 1) ap.push_back(p[i]), i++, k--;
	for (; k > 0; ) {
		if (i >= p.size() - 1) {
			am.push_back(mod(m2[j]));
			j++;
			k -= 2;
			continue;
		}
		if (j >= m2.size()) {
			ap.push_back(p[i] * p[i+1] % MOD);
			i += 2;
			k -= 2;
			continue;
		}
		if (p[i]*p[i+1] > m2[j]) {
			ap.push_back(p[i] * p[i+1] % MOD);
			i += 2;
			k -= 2;
			continue;
		}
		else {
			am.push_back(mod(m2[j]));
			j++;
			k -= 2;
		}
	}
	long long ans = 1;
	for (long long e : ap) {
		ans = mod(ans * e);
	}
	for (long long e : am) {
		ans = mod(ans * e);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8932