#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  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{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=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{
    mint res(*this);
    return res/=a;
  }
};


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

  sort(a.begin(), a.end(), [](ll x, ll y) {
			     return abs(x) > abs(y);
			   });

  ll cnt = 0;
  ll pmin = -1, mmin = -1;
  rep(i,k) {
    if(a[i] < 0) {
      cnt++;
      mmin = i;
    }
    else if(a[i] > 0) pmin = i;
    else {
      cout << 0 << "\n";
      return 0;
    }
  }
  
  if(cnt % 2 == 0) {
    mint res(1);
    rep(i,k) {
      res *= (mint)abs(a[i]);
    }
    cout << res.x << "\n";
    return 0;
  }
  else {
    ll pmax = -1, mmax = -1;
    for (int i = k; i < n; ++i) {
      if(pmax == -1 && a[i] > 0) {
	pmax = i;
      }
      if(mmax == -1 && a[i] < 0) {
	mmax = i;
      }
    }
    if(pmin == -1) {
      if(pmax == -1) {
	mint res(1);
	rep(i,k) {
	  res *= (mint)abs(a[n - 1 - i]);
	}
	cout << (MOD - res.x) % MOD << "\n";
	return 0;
      }
      else {
	mint res(1);
	rep(i,k) {
	  if(i == mmin) continue;
	  res *= (mint)abs(a[i]);
	}
	res *= (mint)abs(a[pmax]);
	cout << res.x << "\n";
	return 0;      	
      }
    }
    
    if(pmax == -1 && mmax == -1) {
      if(a[n-1] == 0) {
	cout << 0 << "\n";
	return 0;
      }
      else {
	mint res(1);
	rep(i,k) {
	  res *= (mint)abs(a[i]);
	}
	cout << (MOD - res.x) % MOD << "\n";
	return 0;
      }
    }
    else if(pmax == -1) {
      mint res(1);
      rep(i,k) {
	if(i == pmin) continue;
	res *= (mint)abs(a[i]);
      }
      res *= (mint)abs(a[mmax]);
      cout << res.x << "\n";
      return 0;      
    }
    else if(mmax == -1) {
      mint res(1);
      rep(i,k) {
	if(i == mmin) continue;
	res *= (mint)abs(a[i]);
      }
      res *= (mint)abs(a[pmax]);
      cout << res.x << "\n";
      return 0;      
    }    
    else {
      if(a[pmax] * a[pmin] < a[mmax] * a[mmin]) {
	mint res(1);
	rep(i,k) {
	  if(i == pmin) continue;
	  res *= (mint)abs(a[i]);
	}
	res *= (mint)abs(a[mmax]);
	cout << res.x << "\n";
	return 0;
      }
      else {
	mint res(1);
	rep(i,k) {
	  if(i == mmin) continue;
	  res *= (mint)abs(a[i]);
	}
	res *= (mint)abs(a[pmax]);
	cout << res.x << "\n";
	return 0;
      }
    }
  }
  
  
  return 0;
}


Measured memory_bytes: 4840