#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]

typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define error(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) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " is " << a << endl;
	err(++it, args...);
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
#define mod 1000000007
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

long long mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

long long mod_product() { return 1LL; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------

bool mysort(ll a,ll b)
{
	return abs(a)>abs(b);
}
const ll inf = 1e10;
ll modpow(ll x,ll y,ll M=mod)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=(ans*x)%M;
		x=(x*x)%M;
		y>>=1;
	}
	return ans;
}

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,k;
	cin>>n>>k;
	lvi a(n);
	ll ans=1;
	ll checkp=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		if(a[i]>0) checkp=1;
		ans=mod_product(ans,a[i]);

	}
	if(k==n)
	{
		cout<<mod_sum(ans,0)<<endl;
		return 0;
	}
	sort(all(a),mysort);
	if(k&1 && checkp==0)
	{
		ll ans=1;
		for(int i=n-1,j=0;j<k;j++,i--)
		{
			ans = mod_product(ans,a[i]);
		}
		cout<<mod_sum(ans,0)<<endl;
		return 0;
	}
	int sign=1;
	ans=1;
	for(int i=0;i<k;i++)
	{
		ans=mod_product(ans,a[i]);
	}
	if(ans>=0)
	{
		cout<<ans<<endl;
		return 0;
	}
	ll inp=inf,inn=inf,outp=inf,outn=inf;
	for(int i=k-1;i>=0;i--)
	{
		if(inp==inf && a[i]>0)
		{
			inp=a[i];
		}
		if(inn==inf && a[i]<0)
		{
			inn=a[i];
		}
	}
	for(int i=k;i<n;i++)
	{
		if(outp==inf && a[i]>0)
		{
			outp=a[i];
		}
		if(outn==inf && a[i]<0)
		{
			outn=a[i];
		}	
	}
	// ll ans1=-inf,ans2=-inf;
	if(inp!=inf && outn!=inf && outp!=inf && inn!=inf)
	{
		if(outp*inp >= outn*inn)
		{
			ans = mod_product(ans,modpow(inn,mod-2),outp);
		}
		else
		{
			ans = mod_product(ans,modpow(inp,mod-2),outn);
		}
	}
	else if(inn!=inf && outp!=inf)
	{
		ans = mod_product(ans,modpow(inn,mod-2),outp);
	}
	else
	{
		ans = mod_product(ans,modpow(inp,mod-2),outn);
	}
	cout<<mod_sum(ans,0)<<endl;
	return 0;
}	

Measured memory_bytes: 4728