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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e5+111;
ll const LG=(ll)log2(N)+1;
ll maxProductSubarrayOfSizeK(vector<ll> A, ll n, ll k) 
{ 
    // sorting given input array 
    sort(all(A)); 
  
    // variable to store final product of all element 
    // of sub-sequence of size k 
    ll product = 1; 
  
    // CASE I 
    // If max element is 0 and 
    // k is odd then max product will be 0 
    
  
    // CASE II 
    // If all elements are negative and 
    // k is odd then max product will be 
    // product of rightmost-subarray of size k 
    if (A[n - 1] <= 0 && (k %2)) { 
        for (ll i = n - 1; i >= n - k; i--) {
            product *= A[i]; 
            product%=MOD;
            product=(product%MOD+MOD)%MOD;
        }
        product=(product%MOD+MOD)%MOD; 
            return product;
        return (product%MOD+MOD)%MOD; 
    } 
        if (A[n - 1] == 0 && (k %2)) 
        return 0; 
    // else 
    // i is current left pointer index 
    ll i = 0; 
  
    // j is current right pointer index 
    ll j = n - 1; 
  
    // CASE III 
    // if k is odd and rightmost element in 
    // sorted array is positive then it 
    // must come in subsequence 
    // Multiplying A[j] with product and 
    // correspondingly changing j 
    if (k%2) { 
        product *= A[j]; 
        product%=MOD;
        j--; 
        k--; 
    } 
        // for(ll i=0;i<n;i++){
        //         cout<<A[i]<<" ";
        // }cout<<endl;
    // CASE IV 
    // Now k is even 
    // Now we deal with pairs 
    // Each time a pair is multiplied to product 
    // ie.. two elements are added to subsequence each time 
    // Effectively k becomes half 
    // Hence, k >>= 1 means k /= 2 
    k/=2; 
        // cout<<i<<" "<<j<<endl;
    // Now finding k corresponding pairs 
    // to get maximum possible value of product 
    for (ll itr = 0; itr < k; itr++) { 
  
        // product from left pointers 
        ll left_product = (A[i] * A[i + 1])%MOD; 
  
        // product from right pointers 
        ll right_product = (A[j] * A[j - 1])%MOD; 
  
        // Taking the max product from two choices 
        // Correspondingly changing the pointer's position 
        if(A[i]*A[i+1]>A[j]*A[j-1]){ 
            product *= A[i];
            product%=MOD; 
            product=(product%MOD+MOD)%MOD;
            product *= A[i+1];
            product%=MOD; 
            product=(product%MOD+MOD)%MOD;
            i += 2; 
        } 
        else { 
            product *= A[j]; 
            product%=MOD;
            product=(product%MOD+MOD)%MOD;
            product *= A[j-1]; 
            product%=MOD;
            product=(product%MOD+MOD)%MOD;
            j -= 2; 
        } 
        // cout<<i<<" "<<j<<endl;
    } 
        
    // Finally return product 
    product=(product%MOD+MOD)%MOD; 
    return product;
} 

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n>>k;
        vector<ll> a(n);
        ll ans=1;
        for(i=0;i<n;i++){
                cin>>a[i];
                ans*=a[i];
                ans%=MOD;
                
        }
        // cout<<ans<<endl;
        cout<<maxProductSubarrayOfSizeK(a,n,k);
        
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 6364