#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element



//---------- 1000000007 ----------
const int MOD = 1000000007;
int m_add(int a, int b)
{
	return (a + b) % MOD;
}
int m_sub(int a, int b)
{
	return (a + MOD - b) % MOD;
}
int m_mul(int a, int b)
{
	return (a * b) % MOD;
}
int m_pow(int x, int n)
{
	if (n == 0) return 1;
	ll res = m_pow((x * x) % MOD, n / 2);
	if (n & 1) res = (res * x) % MOD;
	return res;
}
int m_divide(int a, int b)
{
	return m_mul(a, m_pow(b, MOD - 2));
}
int m_comb(int n, int r)
{
	int i;
	int p = 1;
	for (i = 1; i <= r; i++)
	{
		p = m_mul(p, (n - i + 1));
		p = m_divide(p, i);
	}
	return p;
}
int m_comb_with_rep(int n, int r)
{
	return m_comb(n + r - 1, r);
}


int N, K;
vector<int> A;
vector<int> P;
vector<int> M;
vector<int> work;

signed main()
{
	cin >> N >> K;
	int has_plus = false;
	int zero_cnt = 0;
	int minus_cnt = 0;
	REP(i, N)
	{
		int a;
		cin >> a;
		A.push_back(a);

		if (A[i] == 0)
		{
			zero_cnt++;
		}
		else if (A[i] > 0)
		{
			has_plus = true;
			P.push_back(a);
		}
		else if(A[i] < 0)
		{
			M.push_back(a);
			minus_cnt++;
		}
	}

	if (zero_cnt > (N - K))
	{
		cout << 0 << endl;
		return 0;
	}

	N -= zero_cnt;

	int ans;
	if (!has_plus || N == K)
	{
		int pick = min(minus_cnt, K);

		if (pick % 2 == 0) //正
		{
			ans = 1;
			SORT(A);
			for (int i = 0; i < K; i++)
			{
				ans = m_mul(ans, A[i]);
			}
		}
		else
		{
			ans = 1;
			RSORT(A);
			for (int i = 0; i < K; i++)
			{
				ans = m_mul(ans, A[i]);
			}
		}
	}
	else
	{
		SORT(P);
		RSORT(M);
		int p_index = P.size() - 1;
		int m_index = M.size() - 1;

		for (int i = 0; i < K / 2; i++)
		{
			if (m_index <= 0)
			{
				work.push_back(m_mul(P[p_index], P[p_index - 1]));
				p_index -= 2;
			}
			else if (p_index <= 0)
			{
				work.push_back(m_mul(M[m_index], M[m_index - 1]));
				m_index -= 2;
			}
			else
			{
				int p = P[p_index] * P[p_index - 1];
				int m = M[m_index] * M[m_index - 1];
				if (p > m)
				{
					work.push_back(m_mul(P[p_index], P[p_index - 1]));
					p_index -= 2;
				}
				else
				{
					work.push_back(m_mul(M[m_index], M[m_index - 1]));
					m_index -= 2;
				}
			}
		}

		if (K % 2 == 1)
		{
			work.push_back(P[p_index]);
		}

		ans = 1;
		for (int w : work)
		{
			ans = m_mul(ans, w);
		}
	}

	if (ans < 0)
	{
		ans += MOD;
	}
	cout << ans << endl;
}



Measured memory_bytes: 7944