#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> pa, na;
    REP(i, n){
        ll ai;
        cin >> ai;
        if(ai >= 0){
            pa.push_back(ai);
        }else{
            na.push_back(ai);
        }
    }
    if(n == k){
        mint ans = 1;
        for(ll ai : pa){ ans *= ai; }
        for(ll ai : na){ ans *= ai; }
        cout << ans << endl;
    }else if(pa.size() == 0){
        if(k % 2 == 1){
            sort(ALL(na), greater<ll>());
        }else{
            sort(ALL(na));
        }
        mint ans = 1;
        REP(i, k){ ans *= na.at(i); }
        cout << ans << endl;
    }else{
        sort(ALL(pa));
        sort(ALL(na));

        mint ans = 1;
        if(k % 2 == 1){
            ans *= pa.back();
            pa.pop_back();
            k--;
        }

        vector<ll> prod;
        for(ll i = pa.size() - 1; i >= 1; i -= 2){
            prod.push_back(pa.at(i) * pa.at(i - 1));
            pa.pop_back(); pa.pop_back();
        }
        for(ll i = 0; i + 1 < na.size(); i += 2){
            prod.push_back(na.at(i) * na.at(i + 1));
        }
        sort(ALL(prod));
        for(ll i = prod.size() - 1; i >= 0 && k >= 2; --i){
            ans *= prod.at(i);
            k -= 2;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 6656