#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vec A(n);
    rep(i,n) cin>>A[i];
    sort(all(A),greater<ll>());
    if(k==n){
        mint ans=1;
        rep(i,n) ans*=A[i];
        cout<<ans<<"\n";
        return 0;
    }
    if(A[0]<0&&k%2){
        mint ans=1;
        rep(i,k) ans*=A[i];
        cout<<ans<<"\n";
        return 0;
    }
    vector<P> B;
    rep(i,n){
        if(A[i]==0) B.push_back(P(0,0));
        else B.push_back(P(abs(A[i]),A[i]/abs(A[i])));
    }
    sort(all(B),greater<P>());
    ll h=1;
    mint ans=1;
    rep(i,k) h*=B[i].second,ans*=B[i].first;
    if(h>=0){
        cout<<ans<<"\n";
        return 0;
    }
    ll inf=1e9+1,pminB=inf,mminB=inf,pmaxnB=-inf,mmaxnB=-inf;
    rep(i,k){
        if(B[i].second==1) pminB=min(pminB,B[i].first);
        if(B[i].second==-1) mminB=min(mminB,B[i].first);
    }
    for(int i=k;i<n;i++){
        if(B[i].second>=0) pmaxnB=max(pmaxnB,B[i].first);
        if(B[i].second==-1) mmaxnB=max(mmaxnB,B[i].first);
    }
    if(pminB==inf||mmaxnB==-inf) ans=ans/mminB*pmaxnB;
    else if(mminB==inf||pmaxnB==-inf) ans=ans/pminB*mmaxnB;
    else if(pmaxnB*pminB<mmaxnB*mminB) ans=ans/pminB*mmaxnB;
    else ans=ans/mminB*pmaxnB;
    cout<<ans<<"\n";
}

Measured memory_bytes: 9000