#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

using mint = modint<1000000007>;

int main(){
  ll n,k; cin >> n >> k;
  ll cnto = 0;
  vector<ll>v(n); cin >> v;
  for(auto e:v)cnto += e<=0;
  if(cnto == n && k%2 == 1){
    sort(v.rbegin(),v.rend());
    mint sum(1);
    for(ll i = 0; i < k; ++i)sum *= v[i];
    cout << sum << endl;
    return 0;
  }
  vector<ll> a;
  vector<ll> b;
  for(auto e:v){
    if(e >= 0)a.push_back(e);
    else b.push_back(e);
  }
  sort(a.begin(),a.end());
  sort(b.rbegin(),b.rend());
  ll as(a.size()),bs(b.size());
  ll cnt = 0;
  mint ans(1);
  while(cnt < k){
    if(as >= 2 && bs >= 2 && cnt < k-1){
      if(a[as-1]*a[as-2] > b[bs-1]*b[bs-2]){
	ans *= a[as-1]*a[as-2];
	a.pop_back();a.pop_back();as -= 2;	
      } else {
	ans *= b[bs-1]*b[bs-2];
	b.pop_back();b.pop_back();bs -= 2;
      }
      cnt+=2;
    } else if(as >= 2 && cnt < k-1){
      ans *= a[as-1]*a[as-2];
      a.pop_back();a.pop_back();as -= 2;
      cnt+=2;
    } else if(bs >= 2 && cnt < k-1){
      ans *= b[bs-1]*b[bs-2];
      b.pop_back();b.pop_back();bs -= 2;
      cnt+=2;
    } else {
      if(as > 0){
	ans *= a[as-1];as--;
      } else {
	if(cnt-1 == k){
	  ans *= b[0];bs--;
	} else {
	  ans *= b[bs-1];bs--;
	}
      }
      cnt++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6848