#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n)
		cin >> a[i];

	vector<ll> sig, unsig;
	bool hasZero = false;
	sort(all(a));
	rep(i, n)
	{
		if (a[i] < 0)
		{
			unsig.push_back(a[i] * -1LL);
		}
		else if (a[i] > 0)
		{
			sig.push_back(a[i]);
		}
		else
			hasZero = true;
	}

	sort(sig.begin(), sig.end(), greater<ll>());
	sig.push_back(0);
	unsig.push_back(0);
	ll ans = 1;

	if (n == k)
	{
		for (int i = 0; i < n; i++)
		{
			ans *= a[i];
			ans %= MOD;
			if (ans < 0)
				ans += MOD;
			ans %= MOD;
		}
		cout << ans << endl;
		ret;
	}

	if (unsig.size() <= 2)
	{
		for (int i = 0; i < k; i++)
		{
			if (i < sig.size())
			{
				ans *= sig[i];
				ans %= MOD;
			}
			else
			{
				ans *= unsig[0];
				ans %= MOD;
				if (ans < 0)
					ans += MOD;
				ans %= MOD;
			}
		}
		cout << ans << endl;
		ret;
	}

	if (sig.size() == 1)
	{
		if (k % 2)
		{
			if (hasZero)
			{
				cout << 0 << endl;
				ret;
			}
			for (int i = 2; i < k + 2; i++)
			{
				ans *= -unsig[unsig.size() - i];
				ans %= MOD;
				if (ans < 0)
					ans += MOD;
				ans %= MOD;
			}
		}
		else
			for (int i = 0; i < k; i++)
			{
				if (unsig.size() <= k)
				{
					cout << 0 << endl;
					ret;
				}
				ans *= unsig[i];
				ans %= MOD;
			}
		cout << ans << endl;
		ret;
	}

	ll sii = 0, uii = 0;
	if (k % 2)
	{
		ans *= sig[0];
		sii++;
		for (int i = 1; i < k; i+=2)
		{
			if (sig[sii] == 0 && unsig[uii] == 0)
			{
				cout << 0 << endl;
				ret;
			}
			if (sig[sii] == 0)
			{
				if (unsig[uii] == 0 || unsig[uii + 1] == 0)
				{
					cout << 0 << endl;
					ret;
				}
				ans *= unsig[uii];
				ans %= MOD;
				ans *= unsig[uii + 1];
				ans %= MOD;
				uii += 2;
			}
			else if (unsig[uii] == 0)
			{
				if (sig[sii] == 0 || sig[sii + 1] == 0)
				{
					cout << 0 << endl;
					ret;
				}
				ans *= sig[sii];
				ans %= MOD;
				ans *= sig[sii + 1];
				ans %= MOD;
				sii += 2;
			}
			else
			{
				if (unsig[uii] * unsig[uii + 1] < sig[sii] * sig[sii + 1])
				{
					ans *= sig[sii];
					ans %= MOD;
					ans *= sig[sii + 1];
					ans %= MOD;
					sii += 2;
				}
				else
				{
					ans *= unsig[uii];
					ans %= MOD;
					ans *= unsig[uii + 1];
					ans %= MOD;
					uii += 2;
				}
			}
		}
	}
	else
	{
		for (int i = 0; i < k; i+=2)
		{
			if (sig[sii] == 0 && unsig[uii] == 0)
			{
				cout << 0 << endl;
				ret;
			}
			if (sig[sii] == 0)
			{
				if (unsig[uii]==0 || unsig[uii+1]==0)
				{
					cout << 0 << endl;
					ret;
				}
				ans *= unsig[uii];
				ans %= MOD;
				ans *= unsig[uii + 1];
				ans %= MOD;
				uii += 2;
			}
			else if (unsig[uii] == 0)
			{
				if (sig[sii] == 0 || sig[sii + 1] == 0)
				{
					cout << 0 << endl;
					ret;
				}
				ans *= sig[sii];
				ans %= MOD;
				ans *= sig[sii + 1];
				ans %= MOD;
				sii += 2;
			}
			else
			{
				if (unsig[uii] * unsig[uii + 1] < sig[sii] * sig[sii + 1])
				{
					ans *= sig[sii];
					ans %= MOD;
					ans *= sig[sii + 1];
					ans %= MOD;
					sii += 2;
				}
				else
				{
					ans *= unsig[uii];
					ans %= MOD;
					ans *= unsig[uii + 1];
					ans %= MOD;
					uii += 2;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7168