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


#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define pb push_back



template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}



void mul_self(ll & a, ll b) {
        a += mod;
        b += mod;
        a %= mod;
        b %= mod;
        a *= b;
        a += mod;
        a %= mod;
}


void solve() {
            
           ll N, K;
           cin >> N >> K;
           
           ll A[N + 1];
           vector<ll> pos, neg;
           
           for(ll i = 1; i <= N; i++) {
                cin >> A[i];
                if(A[i] >= 0) {
                        pos.pb(A[i]);
                } else {
                        neg.pb(A[i]);
                }
           }
           
           if(N == K) {
                ll ans = 1;
                
                for(ll i = 1; i <= N; i++) {
                        mul_self(ans, A[i]);
                }
                
                cout << ans << endl;
                return;
           }
           
           sort(neg.begin(), neg.end(), greater<ll>());
           sort(pos.begin(), pos.end());
           
           if((ll)neg.size() == N) {
                    if(K % 2) {
                            ll ans = 1;
                            for(ll i = 0; i < K; i++) {
                                    mul_self(ans, neg[i]);
                            }
                            cout << ans << endl;
                            return;
                    } else {
                            ll ans = 1;
                            for(ll i = N - 1; i > N - 1 - K; i--) {
                                    mul_self(ans, neg[i]);
                            }
                            cout << ans << endl;
                            return;
                    }
           }
           
           ll sineg = neg.size();
           ll sipos = pos.size();
           
           ll totn = 0;
           ll totp = 0;
           
           while((totn + 2 <= sineg) && (totn + 2 <= K)) {
                    totn += 2;
           }
           
           totp = (K - totn);
           
           
           reverse(neg.begin(), neg.end());
           reverse(pos.begin(), pos.end());
           
          
           while((totp + 2 <= sipos) && (totn - 2) >= 0) {
                    ll p1 = pos[totp] * pos[totp + 1];
                    ll p2 = neg[totn - 1] * neg[totn - 2];
                    if(p1 >= p2) {
                            totn -= 2;
                            totp += 2;
                    } else {
                            break;
                    }
           }
           
           ll ans = 1;
           
           for(ll i = 0; i < totp; i++) {
                    mul_self(ans, pos[i]);
           }
           for(ll i = 0; i < totn; i++) {
                    mul_self(ans, neg[i]);
           }
           
           cout << ans << endl;
           return;
           
           
            
           
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   

    int t=1;
   // cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 6704