// Standard Stuff
#include <bits/stdc++.h>
using namespace std;

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <

// Output, Common Containers
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream& os, const set<T>& v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream& os, const map<T,S>& v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef SANYAM1101
	#define trace(args...) do{ cerr << "Trace On! (Line: " << __LINE__ << ")\n"; d_f(string(#args), args); } while(0)
	void d_f(__attribute__((unused)) string str) {}
	template<typename Head, typename... Tails> void d_f(string str, Head H, Tails... T) { cerr << "\t" << str.substr(0, str.find(", ")) << " <=> [" << H << "]\n"; d_f(str.substr(str.find(", ") + 2), T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

void solve(){
	constexpr int MOD = 1e9 + 7;

	auto mul = [](auto f, auto s){
		auto ret = (f * s) % MOD;
		if(ret < 0) ret += MOD;
		return ret;
	};
 
	int n, k;
	cin >> n >> k;
 
	vector<ll> arr(n);
	for(auto& i: arr) cin >> i;
	sort(arr.begin(), arr.end());
 
	ll ans;

	if(n == k or arr.front() >= 0){
		ans = accumulate(arr.end() - k, arr.end(), 1LL, mul);
	}
	else if(arr.back() <= 0){
		if(k & 1) ans = accumulate(arr.end() - k, arr.end(), 1LL, mul);
		else ans = accumulate(arr.begin(), arr.begin() + k, 1LL, mul);
	}
	else{
		ans = 1;
 
		int neg_ptr = 0, pos_ptr = n - 1;
 
		if(k & 1){
			ans = mul(ans, arr.back());
			--pos_ptr;
			--k;
		}
 
		for(int i = 0; i < k - 1; i += 2){
			ll neg_prod = 0;
			if(arr[neg_ptr] < 0 and arr[neg_ptr + 1] < 0)
				neg_prod = arr[neg_ptr] * arr[neg_ptr + 1];
 
			ll pos_prod = 0;
			if(arr[pos_ptr] > 0 and arr[pos_ptr - 1] > 0)
				pos_prod = arr[pos_ptr] * arr[pos_ptr - 1];
 
			if(neg_prod <= pos_prod){
				ans = mul(ans, pos_prod % MOD);
				pos_ptr -= 2;
			}
			else{
				ans = mul(ans, neg_prod % MOD);
				neg_ptr += 2;
			}
		}
	}
 
	cout << ans % MOD << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 4720