#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i,a,b) for(int i=a;i<=b;++i)
const int maxn=2e5+5,mod=1e9+7;
int n,k,fp,fm,bp,bm,de,ext;
LL ans=1;
struct Num
{
	int flag,ab,md;
}a[maxn];
bool cmp(Num x,Num y){
	return x.ab>y.ab;
}
int main()
{
	scanf("%d%d",&n,&k);
	F(i,1,n){
		scanf("%d",&a[i].ab);
		a[i].md=a[i].ab>0?a[i].ab%mod:(mod-(-a[i].ab)%mod)%mod;
		if(a[i].ab<0) a[i].ab=-a[i].ab,a[i].flag=-1;
		else a[i].flag=1;
	}
	sort(a+1,a+1+n,cmp);
	int cur=0;
	F(i,1,k){
		if(a[i].flag==-1) fm=i,cur^=1;
		else fp=i;
	}
	for(int i=n;i>k;--i){
		if(a[i].flag==-1) bm=i;
		else bp=i;
	}
	if(cur){
		if(fp&&fm&&bp&&bm)
		{
			if((LL)a[bm].ab*a[fm].ab>(LL)a[fp].ab*a[bp].ab) de=fp,ext=bm;
			else de=fm,ext=bp;
		} else if(fp&&bm){
			de=fp,ext=bm;
		} else if(fm&&bp){
			de=fm,ext=bp;
		} else {
			F(i,n-k+1,n) ans=ans*a[i].md%mod;
			printf("%lld",ans);
			return 0;
		}
	}
	F(i,1,k)if(i!=de){
		ans=ans*a[i].md%mod;
	}
	if(ext) ans=ans*a[ext].md%mod;
	printf("%lld",ans);
	return 0;
}