#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int n,k,i;
  ll p=1000000007;
  cin >> n >> k;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  
  if(a.at(0)==0&&a.at(n-1)==0){
    cout << 0 << endl;
    return 0;
  }
  
  if(a.at(0)>=0){
    down:
    ll s=1;
    for(i=n-1;i>=n-k;i--){
      s=(s*a.at(i))%p;
    }
    if(s<0){
      s += p;
    }
    cout << s << endl;
    return 0;
  }
  
  
  if(a.at(n-1)<=0){
    if(k%2==1){
      goto down;
    }else{
      ll s=1;
      for(i=0;i<k;i++){
        s=(s*a.at(i))%p;
      }
      if(s<0){
        s += p;
      }
      cout << s << endl;
      return 0;
    }
  }
  
  int l=0,r=n-1;
  for(i=0;i<k;i++){
    if(0-a.at(l)>=a.at(r)){
      l++;
    }else{
      r--;
    }
  }
  if(l%2==1){
    if(l!=0&&(r==n-1||a.at(r)*a.at(r+1)>a.at(l)*a.at(l-1))){
      l--;
      r--;
    }else{
      l++;
      r++;
    }
  }
  ll s=1;
  for(i=0;i<l;i++){
    s=(s*a.at(i))%p;
  }
  for(i=n-1;i>r;i--){
    s=(s*a.at(i))%p;
  }
  if(s<0){
    s += p;
  }
  cout << s << endl;
}