#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 mos() { return 0LL; }
template<typename T, typename... Args>
T mos(T a, Args... args) { return ((a + mos(args...))%mod + mod)%mod; }

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


signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,k;
	cin>>n>>k;
	lvi a(n);
	ll ans=1;
	int checkp=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		if(a[i]>0) checkp=1;
		ans = mop(ans,a[i]);
	}
	if(k==n)
	{
		cout<<mos(0,ans)<<endl;
		return 0;
	}
	if(checkp==0 && k&1)
	{
		sort(all(a),greater<ll>());
		ans=1;
		for (int i = 0; i < k; ++i)
		{
			ans = mop(ans,a[i]);
		}
		cout<<mos(0,ans)<<endl;
		return 0;
	}
	lvi vp,vn;
	for (int i = 0; i < n; ++i)
	{
		if(a[i]>=0) vp.pb(a[i]);
		else vn.pb(a[i]);
	}
	sort(all(vp));
	sort(all(vn),greater<ll>());
	ans=1;
	for(int i=1;i<=k;)
	{
		// error(i,ans);
		if(i==k)
		{
			ans=mop(ans,vp.back());
			// error(ans,vp.back());
			vp.pop_back();
			i++;continue;
		}
		ll sp=vp.size(),sn=vn.size();
		if(sp>=2 && sn>=2)
		{
			if((vp[sp-1]*vp[sp-2])>=(vn[sn-1]*vn[sn-2]))
			{
				ans=mop(ans,vp[sp-1]);
				vp.pop_back();
				i++;continue;
			}
			else
			{
				ans=mop(ans,vn[sn-1],vn[sn-2]);
				vn.pop_back();vn.pop_back();
				i+=2;continue;
			}
		}
		else if(sn<2)
		{
			ans=mop(ans,vp[sp-1]);
			vp.pop_back();
			i++;continue;
		}
		else 
		{
			ans=mop(ans,vn[sn-1],vn[sn-2]);
			vn.pop_back();vn.pop_back();
			i+=2;continue;
		}
	}
	cout<<mos(0,ans)<<endl;
	return 0;
}	

Measured memory_bytes: 6904