#include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 200005;
const LL MOD = 1e9 + 7;

vector<LL>pos,neg,zr;

LL n , k , ara[N];
int32_t main()
{
    cin >> n >> k;
    FOR(i,1,n){
        cin >> ara[i];
        if(ara[i] == 0)zr.push_back(0);
        else if(ara[i] < 0)neg.push_back(-ara[i]);
        else pos.push_back(ara[i]);
    }
    if(pos.size() + neg.size() < k){
        cout << 0 << "\n";
        return 0;
    }
    SORT(pos);
    SORT(neg);

    LL ret = 1;
    if(k % 2 == 1){
        if(pos.size() > 0){
            ret = pos.back();
            pos.pop_back();
            k = k - 1;

            while(k > 0){
                int szpos = pos.size();
                int szneg = neg.size();
                LL A = 0 , B = 0;
                if(szpos >= 2)A = pos[szpos -1] * pos[szpos - 2];
                if(szneg >= 2)B = neg[szneg -1] * neg[szneg - 2];
                if(A > B){
                    ret = (ret * (A % MOD)) % MOD;
                    pos.pop_back();pos.pop_back();
                }
                else{
                    ret = (ret * (B % MOD)) % MOD;
                    neg.pop_back();neg.pop_back();
                }
                k = k - 2;
            }
        }else{
            if(zr.size() > 0)ret = 0;
            else{
                for(int i = 0;i < k;i++)ret = (ret * neg[i]) % MOD;
                ret = -ret;
            }

        }
    }else{
        int take = (neg.size()/2) * 2 + pos.size();

        if(take < k){
            if(zr.size() > 0)ret = 0;
            else{
                for(LL i : pos)neg.push_back(i);
                SORT(neg);
                for(int i = 0;i < k;i++)ret = (ret * neg[i]) % MOD;
                ret = -ret;
            }
        }else{
            while(k > 0){
                int szpos = pos.size();
                int szneg = neg.size();
                LL A = 0 , B = 0;
                if(szpos >= 2)A = pos[szpos -1] * pos[szpos - 2];
                if(szneg >= 2)B = neg[szneg -1] * neg[szneg - 2];
                if(A > B){
                    ret = (ret * (A % MOD)) % MOD;
                    pos.pop_back();pos.pop_back();
                }
                else{
                    ret = (ret * (B % MOD)) % MOD;
                    neg.pop_back();neg.pop_back();
                }
                k = k - 2;
            }
        }

    }
    ret = (ret + MOD) % MOD;
    cout << ret << "\n";
}



Measured memory_bytes: 7592