#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

int n, k;

int mod(LL x) {
	if (x >= 0)
		return x % MOD;
	return (MOD - (abs(x) % MOD)) % MOD;
}

int mul(int a, int b) {
	return mod(1LL * a * mod(b));
}

int bin_pow(int a, int p) {
	int res = 1;
	while (p) {
		if (p & 1)
			res = mul(res, a);
		a = mul(a, a);
		p >>= 1;
	}
	return res;
}

int divs(int a, int b) {
	return mul(a, bin_pow(mod(b), MOD - 2));
}

void solve() {
	cin >> n >> k;
	vector <int> a;
	bool neg = false, zero = false, pos = false;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (x == 0) {
			zero = true;
			continue;
		}
		a.push_back(x);
	}
	if (size(a) < k) {
		cout << 0;
		return;
	}
	sort(all(a), [](int a, int b) { return abs(a) < abs(b); });
	int maxpos = -INF, maxneg = -INF;
	int cntneg = 0;
	int resneg = 1;
	for (int i = 0; i < k; i++) {
		if (a[i] < 0) 
			uax(maxneg, abs(a[i])), cntneg++;
		else
			uax(maxpos, a[i]);
		resneg = mul(resneg, a[i]);
	}
	int minpos = INF, minneg = INF;
	for (int i = k; i < size(a); i++) {
		if (a[i] < 0)
			uin(minneg, abs(a[i]));
		else
			uin(minpos, a[i]);
	}
	if (cntneg % 2) 
		neg = true;
	else {
		bool f1 = (maxpos != -INF && minneg != INF);
		bool f2 = (maxneg != -INF && minpos != INF);
		if (f1 || f2) {
			neg = true;
			if (f1 && f2) {
				if (1LL * minneg * maxneg < 1LL * minpos * maxpos) {
					resneg = mul(resneg, -minneg);
					resneg = divs(resneg, maxpos);
				}
				else {
					resneg = mul(resneg, minpos);
					resneg = divs(resneg, -maxneg);
				}
			}
			else {
				if (f1) {
					resneg = mul(resneg, -minneg);
					resneg = divs(resneg, maxpos);
				}
				else {
					resneg = mul(resneg, minpos);
					resneg = divs(resneg, -maxneg);
				}
			}
		}
	}

	minpos = minneg = INF;
	maxpos = maxneg = -INF;
	cntneg = 0;
	int respos = 1;
	for (int i = size(a) - k; i < size(a); i++) {
		if (a[i] < 0)
			uin(minneg, abs(a[i])), cntneg++;
		else
			uin(minpos, a[i]);
		respos = mul(respos, a[i]);
	}
	for (int i = 0; i < size(a) - k; i++) {
		if (a[i] < 0)
			uax(maxneg, abs(a[i]));
		else
			uax(maxpos, a[i]);
	}
	if (cntneg % 2 == 0)
		pos = true;
	else {
		bool f1 = (maxpos != -INF && minneg != INF);
		bool f2 = (maxneg != -INF && minpos != INF);
		if (f1 || f2) {
			pos = true;
			if (f1 && f2) {
				if (1LL * minneg * maxneg > 1LL * minpos * maxpos) {
					respos = mul(respos, -maxneg);
					respos = divs(respos, minpos);
				}
				else {
					respos = mul(respos, maxpos);
					respos = divs(respos, -minneg);
				}
			}
			else {
				if (f2) {
					respos = mul(respos, -maxneg);
					respos = divs(respos, minpos);
				}
				else {
					respos = mul(respos, maxpos);
					respos = divs(respos, -minneg);
				}
			}
		}
	}

	if (pos) {
		cout << respos;
		return;
	}
	if (zero) {
		cout << 0;
		return;
	}
	cout << resneg;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 4328