#include<bits/stdc++.h>
using namespace std;

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;
const int M = 1e9 + 7;
const int INF = 1e12;
int vec[maxr];

int power(int a, int b) {
	if (a == 0)
		return 0;
	if (b == 0)
		return 1;
	int small = power(a, b / 2);
	int ans = (small * small) % M;
	if (b % 2 == 0)
		return ans;
	return (ans * a) % M;
}

bool comp(pair<int, int> a, pair<int, int> b) {
	return a.first > b.first;
}

int32_t main()
{
	GO;
	int n, k;
	cin >> n >> k;
	int less = 0, greater = 0, zero = 0;
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
		if (vec[i] > 0)
			greater++;
		else if (vec[i] < 0)
			less++;
		else
			zero++;
	}
	if (greater + less < k) {
		cout << 0 << endl;
		return 0;
	}
	// -ve 0
	vector<pair<int, int> > arr(n);
	for (int i = 0; i < n; i++) {
		if (vec[i] > 0)
			arr[i] = {vec[i], 1};
		else
			arr[i] = { -vec[i], 0};
	}
	sort(arr.begin(), arr.end(), comp);
	int count = 0;
	int ans = 1;
	for (int i = 0; i < k; i++) {
		if (arr[i].second == 0)
			count++;
		ans *= arr[i].first;
		ans %= M;
	}
	if (count % 2 == 0) {
		cout << ans << endl;
		return 0;
	}

	int mini_neg = INF, mini_pos = INF;
	for (int i = 0; i < k; i++) {
		// if (arr[i].first == 0)
		// 	continue;
		if (arr[i].second == 0) {
			mini_neg = min(mini_neg, arr[i].first);
		}
		else {
			mini_pos = min(mini_pos, arr[i].first);
		}
	}
	int maxi_pos = -1, maxi_neg = -1;
	for (int i = k; i < n; i++) {
		// if (arr[i].first == 0)
		// 	continue;
		if (arr[i].second == 0) {
			maxi_neg = max(maxi_neg, arr[i].first);
		}
		else {
			maxi_pos = max(maxi_pos, arr[i].first);
		}
	}
	ans = 1;
	if ((mini_neg == INF || maxi_pos == -1)
	        && (mini_pos == INF || maxi_neg == -1)) {
		reverse(arr.begin(), arr.end());
		for (int i = 0; i < k; i++) {
			if (arr[i].second) {
				ans = ((ans * arr[i].first) % M + M) % M;
			}
			else {
				arr[i].first = -arr[i].first;
				ans = ((ans * arr[i].first) % M + M) % M;
			}
		}
		cout << ans << endl;
	}
	else if ((mini_neg == INF || maxi_pos == -1)) {
		for (int i = 0; i < k; i++) {
			if (arr[i].second) {
				ans = ((ans * arr[i].first) % M + M) % M;
			}
			else {
				arr[i].first = -arr[i].first;
				ans = ((ans * arr[i].first) % M + M) % M;
			}
		}
		ans = ((ans * power(mini_pos, M - 2)) % M + M) % M;
		ans = ((ans * (-maxi_neg)) % M + M) % M;
		cout << ans << endl;
	}
	else if ((mini_pos == INF || maxi_neg == -1)) {
		for (int i = 0; i < k; i++) {
			if (arr[i].second) {
				ans = ((ans * arr[i].first) % M + M) % M;
			}
			else {
				arr[i].first = -arr[i].first;
				ans = ((ans * arr[i].first) % M + M) % M;
			}
		}
		ans = ((ans * (-power(mini_neg, M - 2))) % M + M) % M;
		ans = ((ans * maxi_pos + M)) % M % M;
		cout << ans << endl;
	}
	else {
		int a = mini_neg * maxi_neg;
		int b = mini_pos * maxi_pos;
		if (a > b) {
			for (int i = 0; i < k; i++) {
				if (arr[i].second) {
					ans = ((ans * arr[i].first) % M + M) % M;
				}
				else {
					arr[i].first = -arr[i].first;
					ans = ((ans * arr[i].first) % M + M) % M;
				}
			}
			ans = ((ans * power(mini_pos, M - 2)) % M + M) % M;
			ans = ((ans * (-maxi_neg)) % M + M) % M;
			cout << ans << endl;
		}
		else {
			for (int i = 0; i < k; i++) {
				if (arr[i].second) {
					ans = ((ans * arr[i].first) % M + M) % M;
				}
				else {
					arr[i].first = -arr[i].first;
					ans = ((ans * arr[i].first) % M + M) % M;
				}
			}
			ans = ((ans * (-power(mini_neg, M - 2))) % M + M) % M;
			ans = ((ans * maxi_pos) % M + M) % M;
			cout << ans << endl;
		}
	}
	return 0;
}

//!

Measured memory_bytes: 7940