#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int MOD=1e9+7;
typedef long long ll;
ll a[N];
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	int zh=0,fs=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0) zh++;
		else fs++;
	}
	ll sum=1;
	if((m&1)&&(zh==0))
	{
		sort(a+1,a+1+n,greater<int>());
		
		for(int i=1;i<=m;i++) sum=(sum*a[i])%MOD;
	//	cout<<sum<<endl;
	}
	else
	{
		sort(a+1,a+1+n,greater<int>());
		int l=1,r=n;
		while(m>0)
		{
			if(m&1) sum=(sum*a[l])%MOD,l++,m--;
			if(m>=2)
			{
				if(a[l]*a[l+1]>=a[r]*a[r-1]) 
				{
					sum=(sum*a[l]%MOD*a[l+1])%MOD;
					l+=2;
					m-=2;
				}
				else
				{
					sum=(sum*a[r]%MOD*a[r-1])%MOD;
					r-=2;
					m-=2;
					
				}
			}
			
		}
	}
	cout<<(sum%MOD+MOD)%MOD<<endl;
}