//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll fastpow (ll a, ll p){
	if(p == 0) return 1;
	ll z = fastpow(a, p/2);
	z = (z*z)%MOD;
	if(p%2) z = (a*z)%MOD;
	return z;
}

int main(){
	fastio;

	int n, k; cin>>n>>k;
	ll a[n]; forn(i,n) cin>>a[i];

	priority_queue<p64> q1;

	forn(i,n){
		q1.push(mp(abs(a[i]),a[i]));
	}

	ll mi = MOD;
	ll mipos = MOD, mineg = MOD;
	ll ans = 1;
	int taken = 0;
	ll sign = 1;
	ll lastsign = 1;

	while(!q1.empty()){
		auto t = q1.top();
		q1.pop();
		ans = (ans * t.se) % MOD;
		if(t.se != 0) lastsign = t.se / t.fi;
		else lastsign = 0;
		sign = sign * lastsign;
		if(lastsign > 0) mipos = t.se;
		else mineg = t.se;
		taken++;
		if(taken == k) break;
	}

	if(sign < 0){
		ll chans = -MOD, cmans = -MOD;
		ld ratio = -1, prevratio = -1;

		priority_queue<p64> q2 = q1;

		while(!q1.empty()){
			auto t = q1.top();
			q1.pop();
			if(t.se < 0 && mipos != MOD){
				sign = 1;
				chans = (ans * fastpow(mipos, MOD-2))%MOD;
				chans = (chans * t.se)%MOD;
				if(mipos != 0) ratio = abs(((ld)t.se)/(ld)mipos);
				else ratio = 0;
				break;
			}
		}

		cmans = chans;
		if(chans != MOD) prevratio = ratio;

		while(!q2.empty()){
			auto t = q2.top();
			q2.pop();
			if(t.se > 0 && mineg != MOD){
				sign = 1;
				chans = (ans * fastpow(mineg, MOD-2))%MOD;
				chans = (chans * t.se)%MOD;
				if(mineg != 0) ratio = abs(((ld)t.se)/(ld)mineg);
				else ratio = 0;
				break;
			}
		}

		// cout<<ratio<<" "<<prevratio<<ln;
		// cout<<chans<<ln;

		if(ratio > prevratio){
			ans = chans;
		}
		else{
			ans = cmans;
		}
	}

	if(sign != 1){
		while(!q1.empty()) q1.pop();
		forn(i,n){
			q1.push(mp(-abs(a[i]), a[i]));
		}
		taken = 0;
		ans = 1;
		while(!q1.empty()){
			auto t = q1.top();
			q1.pop();
			ans = (ans * t.se) % MOD;
			taken++;
			if(taken == k) break;
		}
	}

	if(ans < 0) ans += MOD;
	cout<<ans<<ln;

	return 0;
}

Measured memory_bytes: 8996