#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 10000000000
#define MAX 500008

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  //vector<ll> plus;
  //vector<ll> minus;
  vector<pair<ll,int>> a;
  int zero=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]>0){
      //plus.push_back(A[i]);
      a.push_back(make_pair(A[i],1));
    }else if(A[i]<0){
      //minus.push_back(-A[i]);
      a.push_back(make_pair(-A[i],-1));
    }else{
      zero++;
    }
  }
  //sort(plus.begin(),plus.end());
  //reverse(plus.begin(),plus.end());
  //sort(minus.begin(),minus.end());
  //reverse(minus.begin(),minus.end());
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  /*
  int n=plus.size();
  int m=minus.end();

  vector<ll> plus_multi(n+1,1);
  vector<ll> minus_multi(m+1,1);
  for(int i=0;i<n;i++){
    plus_multi[i+1]=plus_multi[i]*plus[i];
    plus_multi[i+1]%=MOD;
  }
  for(int i=0;i<m;i++){
    minus_multi[i+1]=minus_multi[i]*minus[i];
    minus_multi[i+1]%MOD;
  }

  if(n+m<K){
    cout<<0<<endl;
    return 0;
  }

  int i=0;
  bool flag=false;
  while(K-i<=n){
    i+=2;
    if(i>m){
      flag=true;
      break;
    }
  }
  ll multi=minus_multi[i]*plus_multi[K-i]%MOD;
  int j=i;
  while(i<=m){

  }
  */

  int n=a.size();
  if(n<K){
    cout<<0<<endl;
    return 0;
  }
  int sign=1;
  for(int i=0;i<K;i++){
    sign*=a.at(i).second;
  }
  if(sign==1){
    ll ans=1;
    for(int i=0;i<K;i++){
      ans*=a.at(i).first;
      ans%=MOD;
    }
    cout<<ans<<endl;
  }else{
    int last_plus=K-1;
    int last_minus=K-1;
    while(a.at(last_plus).second==-1){
      last_plus--;
      if(last_plus<0){
        break;
      }
    }
    while(a.at(last_minus).second==1){
      last_minus--;
    }
    int next_plus=K;
    int next_minus=K;
    while(next_plus<n){
      if(a.at(next_plus).second==1){
        break;
      }
      next_plus++;
    }
    while(next_minus<n){
      if(a.at(next_minus).second==-1){
        break;
      }
      next_minus++;
    }

    if(last_plus>=0&&next_minus<n&&next_plus<n){
      if(a.at(next_minus).first*a.at(last_minus).first>a.at(next_plus).first*a.at(last_plus).first){
        ll ans=1;
        for(int i=0;i<K;i++){
          if(i==last_plus){
            continue;
          }
          ans*=a.at(i).first;
          ans%=MOD;
        }
        ans*=a.at(next_minus).first;
        ans%=MOD;
        cout<<ans<<endl;
      }else{
        ll ans=1;
        for(int i=0;i<K;i++){
          if(i==last_minus){
            continue;
          }
          ans*=a.at(i).first;
          ans%=MOD;
        }
        ans*=a.at(next_plus).first;
        ans%=MOD;
        cout<<ans<<endl;
      }
    }else if(last_plus>=0&&next_minus<n){
      ll ans=1;
      for(int i=0;i<K;i++){
        if(i==last_plus){
          continue;
        }
        ans*=a.at(i).first;
        ans%=MOD;
      }
      ans*=a.at(next_minus).first;
      ans%=MOD;
      cout<<ans<<endl;
    }else if(next_plus<n){
      ll ans=1;
      for(int i=0;i<K;i++){
        if(i==last_minus){
          continue;
        }
        ans*=a.at(i).first;
        ans%=MOD;
      }
      ans*=a.at(next_plus).first;
      ans%=MOD;
      cout<<ans<<endl;
    }else{
      if(zero>0){
        cout<<0<<endl;
      }else{
        ll ans=1;
        reverse(a.begin(),a.end());
        for(int i=0;i<K;i++){
          ans*=a.at(i).first;
          ans%=MOD;
        }
        ans=MOD-ans;
        ans%=MOD;
        cout<<ans<<endl;
      }
    }
  }
}


Measured memory_bytes: 8952