/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

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

using ll = long long;

#define REP(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template<class T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}else return false;}
template<class T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}else return false;}

/*
 * Modint struct
 * library author : @snuke
 * */
const int mod = 1e9 + 7;

struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+mod)%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();}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MAX_N = 200000;

int N,K;
ll a[MAX_N];

bool comp(ll& a,ll &b){
    return abs(a) > abs(b);
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> K;
    REP(i,N) cin >> a[i];
    
    sort(a,a+N,comp);
    
    int nega = 0,posi = 0;
    ll lastNegative,lastPositive;
    
    mint ans = 1;
    
    REP(i,K){
        
        ans *= a[i];
        
        if(a[i] > 0){
            lastPositive = a[i];
            posi++;
        }else if(a[i] < 0){
            lastNegative = a[i];
            nega++;
        }
        
    }
    
    if(nega % 2 == 0){
        
        cout << ans << '\n';
        return 0;
        
    }else{
    
        ll nextPositive = -1,nextNegative = 1;
        
        for(int i = N - 1;i >= K;i--){
        
            if(a[i] < 0) nextNegative = a[i];
            else if(a[i] > 0) nextPositive = a[i];
            
        }
        
        bool discardNegative = (nega > 0) && (nextPositive != -1);
        bool discardPositive = (posi > 0) && (nextNegative != 1);
        
        if(discardNegative && discardPositive){
            
           if(lastNegative * nextNegative < lastPositive * nextPositive){
                
               // discard negative and take positive
               ans /= lastNegative;
               ans *= nextPositive;
           
           }else{
               
               // discard positive and take negative
               ans /= lastPositive;
               ans *= nextNegative;
           
           }
        
        }else if(discardNegative){
            
               // discard negative and take positive
               ans /= lastNegative;
               ans *= nextPositive;
        
        }else if(discardPositive){
            
               // discard positive and take negative
               ans /= lastPositive;
               ans *= nextNegative;
            
        }else{
            
            if(a[N-1] == 0){
            
                ans = 0;
            
            }else{
                
                ans = 1;
                REP(i,K) ans *= (mint) a[N - 1 - i];
            
            }
        
        }
        
        cout << ans << '\n';
        
    }
    
}


Measured memory_bytes: 5092