#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

struct mint {
    LL x; // typedef long long LL;
    mint(LL x=0):x( x >= 0 ? x%mod : x%mod+mod){}
    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;
    }
};

bool comp(LL& a, LL& b){
    if(abs(a) == abs(b)){
        return a > b;
    }
    else return abs(a) > abs(b);
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    LL N,K; cin >> N >> K;
    VL A(N);
    LL cnt[2] = {};
    REP(i,N){
        cin >> A[i];
        if(A[i] >= 0) cnt[0]++;
        else cnt[1]++;
    }
    sort(A.begin(), A.end(), comp);

    if(K == N){
        mint ans = 1;
        REP(i,K) ans *= A[i];
        cout << ans.x << endl;
        return 0;
    }

    bool canpos = false;
    if(min(K/2*2, cnt[1]/2*2) + cnt[0] >= K) canpos = true;

    if(!canpos){

        dump("p2")
        reverse(A.begin(), A.end());
        mint ans = 1;
        REP(i,K){
            ans *= A[i];
        }
        cout << ans.x << endl;

    }else{
        dump("p1")
        mint ans = 1;
        LL pmemo = 1, nmemo = 1;
        bool pex = false, nex = false;
        bool pnx = false, nnx = false;
        LL pperf = -INF, nperf = -INF;
        LL ptmp, ntmp;

        int positive = 1;
        REP(i,K){
            if(A[i] >= 0){
                ans *= A[i];
                pmemo = A[i];
                pex = true;
            }else{
                ans *= A[i];
                nmemo = A[i];
                positive ^= 1;
                nex = true;
            }
        }
        if(positive or ans.x == 0){
            cout << ans.x << endl;
        }else{
            int cur = K;
            while(1){
                if(pnx and nnx) break;
                if(cur == N) break;

                if(A[cur] >= 0){
                    if(nex){
                        if(!pnx) {
                            ptmp = A[cur];
                            pnx = true;
                        }
                    }
                }else{
                    if(pex){
                        if(!nnx){
                            ntmp = A[cur];
                            nnx = true;
                        }
                    }
                }
                cur++;
            }
            if(pnx) pperf = ptmp * pmemo;
            if(nnx) nperf = abs(ntmp * nmemo);
            if(pperf > nperf){
                ans /= nmemo;
                ans *= ptmp;
            }else{
                ans /= pmemo;
                ans *= ntmp;
            }
            cout << ans.x << endl;
        }

    }


}

Measured memory_bytes: 4748