//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;ll k;cin>>k;
  vl a(n);
  rep(i,n)cin>>a[i];
  vector<P>vec(n);
  rep(i,n){
    vec[i].first=abs(a[i]);
    vec[i].second=a[i];
  }
  sort(all(vec));
  reverse(all(vec));
  ll cnt=0;
  rep(i,k){
    if(vec[i].second<0)cnt++;
  }
  if(cnt%2==0){
    ll ans=1;
    rep(i,k){
      ans*=vec[i].first;
      ans%=MOD;
    }
    cout<<ans<<endl;
  }
  else{
    ll minus=0,zero=0,plus=0;
    rep(i,n){
      if(a[i]<0)minus++;
      else if(a[i]==0)zero++;
      else plus++;
    }
    if(k-plus-minus>0){
      cout<<0<<endl;
      return 0;
    }
    if(minus+zero==n||n==k){
      sort(all(a));
      reverse(all(a));
      ll ans=1;
      rep(i,k){
        ans*=(MOD+a[i]);
        ans%=MOD;
      }
      cout<<(ans+MOD)%MOD<<endl;
      return 0;
    }
    
    
    ll ans=1;
    ll k_min=INF;ll k_pla=INF;ll ex_min=-1;ll ex_pla=-1;
    rep(i,k){
      if(vec[i].second>0)k_pla=min(k_pla,vec[i].first);
      if(vec[i].second<0)k_min=min(k_min,vec[i].first);
    }
    for(ll i=k;i<n;i++){
      if(vec[i].second>0)ex_pla=max(ex_pla,vec[i].first);
      if(vec[i].second<0)ex_min=max(ex_min,vec[i].first);
    }
    if(ex_pla*k_pla>=ex_min*k_min||((ex_pla!=-1&&k_min!=INF)&&(k_pla==INF||ex_min==-1))){
      ans*=ex_pla;
      bool used=false;
      rep(i,k){
        if(vec[i].first!=k_min)ans*=vec[i].first;
        else{
          if(used)ans*=vec[i].first;
          else{
            used=true;
          }
        }
        ans%=MOD;
      }
      cout<<ans<<endl;
      return 0;
    }
    else if(ex_pla*k_pla<=ex_min*k_min||((k_pla!=INF&&ex_min!=-1)&&(ex_pla==-1||k_min==INF))){
      ans*=ex_min;
      bool used=false;
      rep(i,k){
        if(vec[i].first!=k_pla)ans*=vec[i].first;
        else{
          if(used)ans*=vec[i].first;
          else{
            used=true;
          }
        }
        ans%=MOD;
      }
      cout<<ans<<endl;
      return 0;
    }
    
    if(zero>0)cout<<0<<endl;
    else{
      sort(all(a));
      reverse(all(a));
      ll ans=1;
      rep(i,n){
      ans*=(MOD+a[i]);
      ans%=MOD;
      }
      cout<<ans<<endl;
    }
  }
  
}

Measured memory_bytes: 7964