// Author : Syed Mujtaba
// Seek knowledge from the Cradle to the Grave !!
// https://www.linkedin.com/in/syed-mujtaba

#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 int             long long
#define ld              long double
#define ll              long long
#define pb              push_back
#define fi              first
#define se              second
#define mod             1000000007  //998244353// 1e9 + 7
#define inf             1000000007 // 1e9 + 7
#define MAX             8000000000000000064LL
#define MIN            -8000000000000000064LL
#define MAXN            200064
#define mt              make_tuple
#define eps             1e-6
#define endl            '\n'
#define test            int _o_; cin>>_o_; while(_o_--)
#define fast_io         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #define tree            tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
// int fact[1000007]={0};
// int spf[(int)(1e7) + 20];
// bool prime[(int)((1e7) + 20)];
// int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
// void sp(int n){spf[1]=1;for(int i=2;i<n;i++)spf[i]=i;for(int i=4;i<n;i+=2)spf[i]=2;for(int i=3;i*i<n;i++){if(spf[i]==i){for(int j=i*i;j<n;j+=i)if(spf[j]==j)spf[j]=i;}}}
// void sieve(int n){memset(prime,true,sizeof(prime) );for(int p=2;p*p<=n;p++){if(prime[p]==true)for(int i=p*p;i<=n;i+=p)prime[i]=false;}prime[0]=false;prime[1]=false;}
// int xyp(int x,int y){int res=1;while(y>0){if(y%2==1) res=(res*x)%mod;x=(x*x)%mod;y/=2;}return res%mod;}
// int inv(int x){return xyp(x,mod - 2);}
// int inv_euclid(int a, int m = mod){int m0 = m;int y = 0, x = 1;if (m == 1)return 0;while (a > 1){int q = a / m;int t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
// void init() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
// int ncr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[r],mod-2)))%mod; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res;}
// int npr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res; }
// bool isp(int a){if(a == 2)return true;if(a == 1)return false;for(int x= 2; x <= sqrt(a) + 1; x++)if(a % x == 0)return false;return true;}
int add(int a, int b){return (a%mod + b%mod + ((MAX)/mod)*mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + ((MAX)/mod)*mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + ((MAX)/mod)*mod)%mod;}
// #define p_set tree< pair<int,int> ,  null_type ,  less<pair<int,int>> ,  rb_tree_tag ,  tree_order_statistics_node_update>
// #define i_set tree< int ,  null_type ,  less< int > ,  rb_tree_tag ,  tree_order_statistics_node_update>
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// int dx[] = {+1, -1, 0, 0};
// int dy[] = {0, 0, +1, -1};
signed main()
{
	fast_io
	int n;
	int k;
	cin >> n >> k;
	int w;
	bool ze = 0;
	multiset < int, greater < int > > po;
	multiset <int> ne;
	bool tp = 1;
	for(int i = 0; i < n; i++){
		cin >> w;
		if(w >= 0)po.insert(w);
		else ne.insert(w);
		if(w==0)ze=1;
	}
	int ans = 1;
	if(k%2==0)
	{
		if(po.size() + (ne.size() / 2)*2 < k) tp = 0;
	}
	else
	{
		int pos = po.size();
		int negg = ne.size();
		int ev = k - 1;
		ev -= ((negg / 2) * 2);
		if(ev > 0)
		{
			pos -= ev;
		}
		if(pos <= 0)tp = 0;
	}
	// cout << tp << endl;
	// // for(auto z : ne)
	// // {
	// // 	cout << z << " ";

	// // }
	// cout << endl;
	if(!tp)
	{
		while(k >= 2)
		{
			int p1 = MAX, p2 = MAX;
			if(po.size() >= 2)
			{
				auto it = po.end();
				it--;
				p1 = (*it) * (*(--it));	
			}
			if(ne.size() >= 2)
			{
				auto it = ne.end();
				it--;
				p2 = (*it) * (*(--it));
				// cout << p2 << endl;
			}
			if(p1 == MAX && p2 == MAX)
			{
				break;
			}
			else
			{
				k -= 2;
				if(p1 <= p2)
				{
					ans = mul(ans, p1 % mod);
					auto it = po.end();
					po.erase((--po.end()));
					po.erase((--po.end()));					
					// po.erase(po.begin());				
				}
				else
				{
					ans = mul(ans, p2 % mod);
					ne.erase(--ne.end());
					ne.erase(--ne.end());
				}
			}
		}
	}
	else
	{
		while(k >= 2)
		{
			int p1 = MIN, p2 = MIN;
			if(po.size() >= 2)
			{
				auto it = po.begin();
				p1 = (*it) * (*(++it));	
			}
			if(ne.size() >= 2)
			{
				auto it = ne.begin();
				p2 = (*it) * (*(++it));
			}
			if(p1 == MIN && p2 == MIN)
			{
				break;
			}
			else
			{
				k -= 2;
				if(p1 > p2)
				{
					ans = mul(ans, p1 % mod);
					po.erase(po.begin());
					po.erase(po.begin());				
				}
				else
				{
					ans = mul(ans, p2 % mod);
					ne.erase(ne.begin());
					ne.erase(ne.begin());
				}
			}
		}
	}
	if(k == 0)
	{
		cout << ans << '\n';
		return 0;
	}
	else
	{
		while(k--)
		{
			if(po.size() == 0)
			{
				ans = mul(ans, *(--ne.end()));
				ne.erase(--ne.end());
			}
			else
			{
				ans = mul(ans, *po.begin());
				po.erase(po.begin());
			}
		}
	}
	cout << ans << '\n';
	


}

Measured memory_bytes: 13008