//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll p=0,z=0,m=0;
    REP(i,n){
        cin >> a[i];   
        if(a[i]>0){
            p++;
        }else if(a[i]==0){
            z++;
        }else{
            m++;
        }
    }
    if(z==0&&((p==0&&k%2==1LL)||(k==n&&m%2==1LL))){
        //minus
        REP(i,n){
            a[i] = abs(a[i]);
        }
        sort(ALL(a));
        mint ans(1);
        REP(i,k){
            ans *= mint(a[i]);
        }
        ans *= mint(-1);
        cout << ans.x << endl;
    }else if(z>0&&(p+m-(m%2)<k)){
        //zero
        cout << 0 << endl;
    }else{
        vector<pair<ll,ll> > pa(n);
        REP(i,n){
            if(a[i]>0){
                pa[i] = make_pair(a[i], 1LL);
            }else if (a[i] == 0){
                pa[i] = make_pair(a[i], 1LL);
            }else{
                pa[i] = make_pair((-a[i]), -1LL);
            }
        }
        sort(rALL(pa));
        ll cnt = 0;
        mint t(1);
        REP(i,k){
            if(pa[i].se==-1LL) cnt++;
            t *= mint(pa[i].fi);
        }
        if(cnt%2==0){
            cout << t.x << endl;
        }else{
            mint t1(1);
            ll x1,x2;
            bool f1 = false; 
            REP(i,n){
                if(i<k){
                    if(pa[i].se==-1LL){
                        x1 = pa[i].fi;
                    }
                }else{
                    if(pa[i].se==1LL){
                        f1 = true;
                        x2= pa[i].fi;
                        break;
                    }
                }
            }
            ll y1,y2;
            bool f2 = false; 
            REP(i,n){
                if(i<k){
                    if(pa[i].se==1LL){
                        y1 = pa[i].fi;
                        f2 = true;
                    }
                }else{
                    if(pa[i].se==-1LL){
                        y2 = pa[i].fi;
                        break;
                    }
                }
                if(i==n-1){
                    f2 = false;
                    break;
                }
            }
            if(f1&&f2){
                if(x2*y1>=x1*y2){
                    t /= mint(x1);
                    t *= mint(x2);
                    cout << t.x << endl;
                }else{
                    t /= mint(y1);
                    t *= mint(y2);
                    cout << t.x << endl;
                }
            }else if(f1){
                t /= mint(x1);
                t *= mint(x2);
                cout << t.x << endl;
            }else{
                t /= mint(y1);
                t *= mint(y2);
                cout << t.x << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 7924