#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct mint {
    long long x;
    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(long long 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;
    }
};

long long modp(long long a) {
    long long res = a % MOD;
    if (res < 0) res += MOD;
    return res;
}

void Main(){
    int N,K; cin >> N >> K;
    VL A(N); REP(i,N) cin >> A[i]; SORT(A);

    VL a,b; REP(i,N) if(A[i]<0) b.push_back(-A[i]); else a.push_back(A[i]);
    REVERSE(a);
    int n1 = a.size(), n2 = b.size();
    VL sa(n1+1,1), sb(n2+1,1);
    REP(i,n1) (sa[i+1] = sa[i]*a[i]) %= MOD;
    REP(i,n2) (sb[i+1] = sb[i]*b[i]) %= MOD;

    if(N==K){
        mint ans(1);
        REP(i,N) ans *= A[i];
        cout << ans.x << en;
        return;
    }
    else if(n1==0){
        mint ans(1);
        if(K%2){
            REVERSE(A);
            REP(i,K) ans *= A[i];
        }
        else{
            REP(i,K) ans *= A[i];
        }
        cout << ans.x << en;
        return;
    }
    else if(n2==0){
        mint ans(1);
        REVERSE(A);
        REP(i,K) ans *= A[i];
        cout << ans.x << en;
        return;
    }

    mint ans(1);

    auto c = [&](ll a, ll b){
        return abs(a)>abs(b);
    };
    sort(ALL(A),c);
    ll m = 0, last;
    REP(i,K){
        if(A[i]<0){
            m++;
        }
        last = A[i];
    }

    vector<mint> s(N+1,1); REP(i,N) s[i+1] = s[i]*A[i];
    if(m%2){
        ans = s[K];
        ll mxp1=LINF,mxp2=-LINF,mxm1=-LINF,mxm2=LINF;
        for(int i=K-1; i>=0; i--){
            if(A[i]<0) chmax(mxm1,A[i]);
            else chmin(mxp1,A[i]);
        }
        for(int i=K; i<N; i++){
            if(A[i]<0) chmin(mxm2,A[i]);
            else chmax(mxp2,A[i]);
        }

        long double v1=0,v2=0;
        if(mxp1<LINF && mxm2<LINF){
            v1 = (long double)-mxm2 / (long double)mxp1;
        }
        if(mxm1>-LINF && mxp2>-LINF){
            v2 = (long double)-mxp2 / (long double)mxm1;
        }

        if(v1>v2){
            ans /= mxp1;
            ans *= mxm2;
        }
        else{
            ans /= abs(mxm1);
            ans *= -1;
            ans *= mxp2;
        }
    }
    else{
        ans = s[K];
    }
    cout << ans.x << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 9484