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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll mul(ll a,ll b,ll P){return b?(mul(a*2%P,b>>1,P)+(b&1?a:0))%P:0;}
ll pow1(ll p,ll d, ll P){return d?mul(pow1(mul(p,p,P),d>>1,P),(d&1?p%P:1),P):1;}

V prime;
bool is_composite[MAXN];
void sieve (ll n){
	std::fill (is_composite, is_composite + n, false);
	rep(i,2,n){
		if(!is_composite[i]) prime.pb(i);
		for(ll j = 0; j < prime.size() && i*prime[j] < n; ++j){
			is_composite[i*prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}
ll modInverse(ll a, ll m){
	ll m0=m,y=0,x=1;
	if(m==1) return 0;
	while(a>1){
		ll q=a/m,t=m;
		m=a%m;
		a=t; 
		t=y;

		y = x-q*y; 
		x = t;
	}
	if(x<0) x += m0;
	return x; 
}

ll f(ll a,ll b){return abs(a)<abs(b);}

void doit(){
	gi(n); gi(k);
	ll a[n],p=1,neg=0;
	rep(i,0,n) a[i]=read();
	if(n==k){
		rep(i,0,n){
			p*=a[i];
			if(p<0) p=M-abs(p)%M;
			p%=M;
		}
		cout<<p;
		return;
	}
	sort(a,a+n,f);
	if(!a[n-k]){
		cout<<0;
		return;
	}
	rep(i,n-k,n) neg+=a[i]<0;
	if(neg+1&1){
		rep(i,n-k,n){
			p*=a[i];
			if(p<0) p=M-abs(p)%M;
			p%=M;
		}
		cout<<p;
		return;
	}
	if(neg==k){
		rep(i,n-k+1,n){
			p*=a[i];
			if(p<0) p=M-abs(p)%M;
			p%=M;
		}
		ll f=0;
		per(i,0,n-k+1)
			if(a[i]>=0){
				p*=a[i];
				p%=M;
				f=1;
				break;
			}
		if(f)cout<<p;
		else{
			p=1;
			rep(i,0,k){
				p*=a[i];
				if(p<0) p=M-abs(p)%M;
				p%=M;
			}
			cout<<p;
		}
		return;
	}
/*	if(a[n-k-1]==0){
		cout<<0;
		return;
	}*/
	ll pos1=M,pos2=M,neg1=M,neg2=M;
	rep(i,n-k,n){
		if(pos1==M && a[i]>0) pos1=a[i];
		if(neg1==M && a[i]<0) neg1=a[i];
		if(pos1-M && neg1-M) break;
	}
	per(i,0,n-k){
		if(pos2==M && a[i]>=0) pos2=a[i];
		if(neg2==M && a[i]<0) neg2=a[i];
		if(pos2-M && neg2-M) break;
	}
	if(pos2==M){
		p=M-abs(neg2)%M;
		ll f=0;
		rep(i,n-k,n){
			if(a[i]!=pos1 || f){
				p*=a[i];
				if(p<0) p=M-abs(p)%M;
				p%=M;
			}
			if(a[i]==pos1) f=1;
		}
		cout<<p;
		return;
	}
	if(neg2==M){
		p=pos2;
		ll f=0;
		rep(i,n-k,n){
			if(a[i]!=neg1 || f){
				p*=a[i];
				if(p<0) p=M-abs(p)%M;
				p%=M;
			}
			if(a[i]==neg1) f=1;
		}
		cout<<p;
		return;
	}
	if(neg1*neg2>pos1*pos2){
		p=M-(-neg2)%M;
		ll f=0;
		rep(i,n-k,n){
			if(a[i]!=pos1 || f){
				p*=a[i];
				if(p<0) p=M-abs(p)%M;
				p%=M;
			}
			if(a[i]==pos1) f=1;
		}
		cout<<p;
		return;
	}
	p=pos2;
	ll f=0;
	rep(i,n-k,n){
		if(a[i]!=neg1 || f){
			p*=a[i];
			if(p<0) p=M-abs(p)%M;
			p%=M;
		}
		if(a[i]==neg1) f=1;
	}
	cout<<p;
/*	if(a[n-k-1]<0){
		ll f=0;
		p=1;
		rep(i,n-k+1,n){
			if(a[i]<0||f){
				p*=a[i];
				if(p<0) p=M-abs(p)%M;
				p%=M;
			}
			if(a[i]>0) f=1;
		}
		p*=a[n-k-1];
		if(p<0)p=M-abs(p)%M;
		p%=M;
		cout<<p;
		return;
	}
	ll f=0;
	rep(i,n-k+1,n){
		if(a[i]>0||f){
			p*=a[i];
			if(p<0) p=M-abs(p)%M;
			p%=M;
		}
		if(a[i]<0) f=1;
	}
	p*=a[n-k-1];
	if(p<0)p=M-abs(p)%M;
	p%=M;
	cout<<p;*/

}
int main(){
	//for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}


Measured memory_bytes: 5180