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

const int mod = 1e9 + 7;

long long solve(vector<int>& a, int n, int k) {
	long long res = 1;
	
	if (a[n-1] == 0 && k%2) {
		return 0;
	}
	
	if (a[n-1] < 0 && k%2) {
		for (int i = n-1; i >= n-k; i--) {
			res = (res*a[i]) % mod;
		}
		return (res + mod) % mod;
	}
	
	if (a[n-1] > 0 && k%2) {
		res = a[n-1];
		--n; --k;
	}
	
	// k is even
	k /= 2;
	int l = 0, r = n-1;
	while (k--) {
		long long left = 1LL * a[l] * a[l+1], right = 1LL * a[r] * a[r-1];
		if (left > right) {
			res = (res*(left%mod))%mod;
			l += 2;
		} else {
			res = (res*(right%mod))%mod;
			r -= 2;
		}
	}
	return (res + mod) % mod;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	
	cout << solve(a, n, k) << endl;
}