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

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

/*
5 4 2 1 1
4 4  
// }
*/

const int MOD = 1E9 + 7;

int binpow(int base, int e) {
	int ret = 1;
	while(e) {
		if(e & 1)
			ret = ret * base % MOD;
		base = base * base % MOD;
		e >>= 1;
	} 
	return ret;
}

int inverse(int x) {
	return binpow(x % MOD, MOD - 2);
}

int main() {
	int n, k;
	cin >> n >> k;
	vi pos, neg;
	for(int i = 0; i  < n; i++) {
		int x;
		cin >> x;
		if(x >= 0)
			pos.pb(x);
		else
			neg.pb(x);
	}

	ll res = 1;
	sort(all(pos), greater<int>());
	sort(all(neg));

	int need = k;
	int p1 = 0, p2 = 0;
	while(need > 1 && (p1 + 1 < sz(pos) || p2 + 1 < sz(neg))) {
		if(p1 + 1 < sz(pos) && p2 + 1 < sz(neg)) {
			if((ll) pos[p1] * pos[p1 + 1] > (ll) neg[p2] * neg[p2 + 1]) {
				res = res * pos[p1] % MOD * pos[p1 + 1] % MOD;
				p1 += 2;
				need -= 2;
			}	
			else {
				res = res * neg[p2] % MOD * neg[p2 + 1] % MOD;
				p2 += 2;
				need -= 2;
			}
		}
		else if(p1 + 1 < sz(pos)) {
			res = res * pos[p1] % MOD * pos[p1 + 1] % MOD;
			p1 += 2;
			need -= 2;
		}
		else {
			res = res * neg[p2] % MOD * neg[p2 + 1] % MOD;
			p2 += 2;
			need -= 2;
		}
	}

	assert(need <= 2);

	if(need == 0) {
		cout << (res % MOD + MOD) % MOD << '\n';
		return 0;
	}

	if(need == 1) {
		if(p1 < sz(pos) && p1 > 0 && p2 + 1 < sz(neg)) {
			if((ll) pos[p1] * pos[p1 - 1] >= (ll) neg[p2] * neg[p2 + 1])
				res = res * pos[p1++] % MOD;
			else
				res = res * inverse(pos[p1 - 1]) % MOD * neg[p2++] % MOD * neg[p2++] % MOD;
		}
		else if(p1 < sz(pos))
			res = res * pos[p1++] % MOD;
		else if(p1 > 0 && p2 + 1 < sz(neg)) {
			res = res * inverse(pos[p1 - 1]) % MOD * neg[p2++] % MOD * neg[p2++] % MOD;
		}
		else {
			reverse(all(pos));
			reverse(all(neg));

			res = (neg[0] % MOD + MOD) % MOD;
			need = k - 1, p1 = 0, p2 = 1;
			while(need > 1 && (p1 + 1 < sz(pos) || p2 + 1 < sz(neg))) {
				if(p1 + 1 < sz(pos) && p2 + 1 < sz(neg)) {
					if((ll) pos[p1] * pos[p1 + 1] < (ll) neg[p2] * neg[p2 + 1]) {
						res = res * pos[p1] % MOD * pos[p1 + 1] % MOD;
						p1 += 2;
						need -= 2;
					}	
					else {
						res = res * neg[p2] % MOD * neg[p2 + 1] % MOD;
						p2 += 2;
						need -= 2;
					}
				}
				else if(p1 + 1 < sz(pos)) {
					res = res * pos[p1] % MOD * pos[p1 + 1] % MOD;
					p1 += 2;
					need -= 2;
				}
				else {
					res = res * neg[p2] % MOD * neg[p2 + 1] % MOD;
					p2 += 2;
					need -= 2;
				}
			}

			assert(need == 0);

		}
		cout << (res % MOD + MOD) % MOD << '\n';
		return 0;
	}

	if(need == 2) {
		res = 1;
		for(int x : pos)
			res = res * x % MOD;
		for(int x: neg)
			res = res * x % MOD;
		cout << (res % MOD + MOD) % MOD << '\n';
	}
}


Measured memory_bytes: 4308