#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;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

const int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


void test_case(){
	int n , k; cin >> n >> k;
	vector<int> s,t,a(n);
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
		if( a[i] < 0 )
			t.push_back(a[i]);
		else
			s.push_back(a[i]);
	}
	int S = s.size();
	int T = t.size();
	
	bool ok = false;
	if(S > 0){
		if(n == k) ok = (T%2 == 0);
		else ok = true;
	}
	else{
		ok = (k%2==0);
	}
	mint ans = 1;
	if(!ok){
		sort(a.begin(),a.end(),[](int x,int y){
			return abs(x) < abs(y);
		});
		for(int i = 0 ; i < k ; i++)
			ans*=a[i];
	}
	else{
		sort(s.begin(),s.end());
		sort(t.rbegin(),t.rend());
		if(k%2 == 1) {
			ans *= s.back();
			s.pop_back();
		}
		vector<ll> p;
		while((int)s.size() >= 2) {
			ll x = s.back() ; s.pop_back();
			x *= s.back(); s.pop_back();
			p.push_back(x);
		}
		while((int)t.size() >= 2) {
			ll x = t.back() ; t.pop_back();
			x *= t.back(); t.pop_back();
			p.push_back(x);
		}
		sort(p.rbegin(),p.rend());
		for(int i = 0 ; i < k /2 ; i++)
			ans *= p[i];
	}
	cout<<ans<<"\n";
	return;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 6376