#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll modpow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    ll n,k; cin >> n >> k;
    vpl b(n);
    vl a(n); rep(i,n) cin >> a[i];
    rep(i,n){
        b[i].first = abs(a[i]);
        if(a[i] == 0) b[i].second = 0;
        else if(a[i] < 0) b[i].second = -1;
        else b[i].second = 1;
    }
    sort(rall(b));
    if(b[k-1].first == 0){
        puts("0");
        return 0;
    }
    ll ans = 1;
    vl minus;
    vl plus;
    rep(i,k){
        ans *= b[i].first;
        ans %= mod;
        if(b[i].second < 0) minus.push_back(b[i].first);
        else if(b[i].second > 0) plus.push_back(b[i].first);
    }
    if(minus.size() % 2 == 0){
        cout << ans << "\n";
        return 0;
    }
    sort(all(minus)); sort(all(plus));
    ll mi = 0, pl = 0;
    for(int i=k; i<n; i++){
        if(b[i].second < 0){
            mi = b[i].first;
            break;
        }
    }
    for(int i=k; i<n; i++){
        if(b[i].second > 0){
            pl = b[i].first;
            break;
        }
    }
    ll A = minus[0] * mi;
    if(plus.empty()){
        if(pl == 0){
            ans = 1;
            sort(all(b));
            rep(i,k){
                ans *= b[i].first;
                ans %= mod;
            }
            ans *= mod - 1;
            ans %= mod;
        }else{
            ans *= pl;
            ans %= mod;
            ans *= modpow(minus[0],mod-2,mod);
            ans %= mod;
        }
        cout << ans << "\n";
        return 0;
    }
    ll B = plus[0] * pl;
    if(A == B && A == 0){
        ans = 1;
        sort(all(b));
        rep(i,k){
            ans *= b[i].first;
            ans %= mod;
        }
        ans *= mod - 1;
        ans %= mod;
        cout << ans << "\n";
    }else{
        if(A > B){
            ans *= mi;
            ans %= mod;
            ans *= modpow(plus[0],mod-2,mod);
            ans %= mod;
        }else{
            ans *= pl;
            ans %= mod;
            ans *= modpow(minus[0],mod-2,mod);
            ans %= mod;
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 10296