#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    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();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    ll N, K;
    cin >> N >> K;
    deque<ll> A(N),M,P,Z,B(N);
    ll np=0,nm=0;
    rep(i,N){
        cin >> A[i];
        if(A[i] < 0){
            M.push_back(A[i]);
            nm++;
        }
        if(A[i] >= 0){
            P.push_back(A[i]);
            np++;
        }
    }
    bool flag = true;
    /*if(np >= K){
        flag = true;
    }else if(np == 0 && K%2 == 0){
        flag = true;
    }else if(np == 0 && K%2 == 1){
        flag = false;
    }else if(np > 0){
        flag = true;
    }*/
    if (np > 0) {
        if (N == K) flag = (nm%2==0);
        else flag = true;
    } else {
        flag = (K%2==0);
    }

    if(flag){
        sort(P.rbegin(), P.rend());
        sort(M.begin(), M.end());
        mint ans = 1;
        if(K%2 == 1){
            ans *= P.front();
            P.pop_front();
        }
        vector<ll> v;
        ll tmp = 1;
        //cout << "b "<<P.size() << " " << M.size() << endl;
        ll pp = P.size();
        rep(i, (pp/2)*2){
            if(i%2 == 0){
                tmp = 1;
                tmp *= P.front();
                P.pop_front();
            }else{
                tmp *= P.front();
                P.pop_front();
                v.push_back(tmp);
            }
        }
        tmp = 1;
        ll mm = M.size();
        rep(i, (mm/2)*2){
            if(i%2 == 0){
                tmp = 1;
                tmp *= M.front();
                M.pop_front();
            }else{
                tmp *= M.front();
                M.pop_front();
                v.push_back(tmp);
            }
        }
        //cout << "c "<< v.size() << endl;
        sort(v.rbegin(),v.rend());
        rep(i,K/2){
            ans *= v[i];
            //cout << "a " << v[i] << endl;
        }    
        
        cout << ans << endl;
        return 0;
    }else{
        rep(i,N){
            B[i] = abs(A[i]);
        }
        sort(B.begin(), B.end());
        mint ans = 1;
        rep(i,K){
            ans *= B[i];
        }
        cout << mint(0) - ans << endl;
    }
}

Measured memory_bytes: 9172