/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

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

using ll = long long;

#define REP(i,n) for(int i = 0;i < n;i++)
#define all(x) x.begin(),x.end()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int)v.size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template<class T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}else return false;}
template<class T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}else return false;}
/*
 * Modint struct
 * library author : @snuke
 * */
const int mod = 1e9 + 7;
struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+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();}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int64_t n, k;
    cin >> n >> k;
    vector<int64_t> pos, nega, zero;
    REP(i, n) {
        int64_t foo;
        cin >> foo;
        if (foo > 0) pos.push_back(foo);
        else if (foo == 0) zero.push_back(foo);
        else nega.push_back(foo);
    }

    sort(all(pos));
    reverse(all(pos));
    sort(all(nega));

    if(pos.size() + nega.size() < k){
        cout << 0 << '\n';
        return 0;
    }

    /////////////////////////////////

    mint ans = 1;
    if(nega.size() == 1){
        if(pos.size() >= k){
            REP(i,k) ans *= (mint)pos[i];
            cout << ans << '\n';
            return 0;
        }else{
            if(zero.size()){
                cout << 0 << '\n';
                return 0;
            }else{
                for(auto i : pos) ans *= (mint)i;
                for(auto i : nega) ans *= (mint)i;
                cout << ans << '\n';
                return 0;
            }
        }
    }else{
        vector<pair<ll,ll>> na;
        for(auto i : pos) na.emplace_back(i,i);
        for(auto i : nega) na.emplace_back(-i,i);

        sort(all(na));
        reverse(all(na));

        int negac = 0;
        int posc = 0;
        ll lastnega = 1;
        ll lastpos = 1;

        REP(i,k){
            if(na[i].second < 0){
                lastnega = na[i].second;
                negac++;
            }else posc++,lastpos = na[i].second;
            ans *= na[i].second;
        }
        if(negac % 2 == 0){
            cout << ans << '\n';
            return 0;
        }else{
            int sz = na.size();
            //for(int i = k;i < sz;i++){
            //    if(na[i].second > 0){
            //        ans /= lastnega;
            //        ans *= na[i].second;
            //        cout << ans<< '\n';
            //        return 0;
            //    }else if(posc){
            //        ans /= lastpos;
            //        ans *= na[i].second;
            //        cout << ans << '\n';
            //        return 0;
            //    }
            //}

            bool nn = 0,np = 0;
            ll nextnega = 0,nextpos = 0;

            for(int i = k;i < sz;i++){
                if(!nn && na[i].second < 0) {
                    nn = 1;
                    nextnega = na[i].second;
                }
                if(!np && na[i].second > 0){
                    np = 1;
                    nextpos = na[i].second;
                }
            }

            if(nn && np && negac && posc){
                if(nextnega * lastnega > nextpos * lastpos){
                    ans /= (mint) lastpos;
                    ans *= nextnega;
                }else{
                    ans /= (mint)lastnega;
                    ans *= nextpos;
                }
                cout << ans << '\n';
                return 0;
            }else{
                if(nn && posc){
                    ans /= (mint)lastpos;
                    ans *= (mint) nextnega;
                    cout << ans << '\n';
                    return 0;
                }else if(np && negac){
                    ans /= (mint)lastnega;
                    ans *= (mint) nextpos;
                    cout << ans << '\n';
                    return 0;
                }

            }

            if(zero.size()){
                cout << 0 << '\n';
                return 0;
            }else{
                reverse(all(na));
                ans = 1;
                REP(i,k)ans *= na[i].second;
                cout << ans << '\n';
                return 0;
            }
        }
    }

}


Measured memory_bytes: 8976