#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a.at(i);
    }
    sort(ALL(a), [](ll x, ll y){ return abs(x) > abs(y); });

    vector<ll> pn, nn;
    ll sign = 1;
    REP(i, k){
        if(a.at(i) >= 0){
            pn.push_back(a.at(i));
        }else{
            nn.push_back(a.at(i));
        }
        if(a.at(i) < 0){
            sign *= -1;
        }else if(a.at(i) == 0){
            sign = 0;
        }
    }

    if(sign < 0){
        assert(nn.size() > 0);
        bool found_p = false, found_n = false;
        ll pos_num, neg_num;
        for(ll i = k; i < n; ++i){
            if(!found_p && a.at(i) >= 0){
                found_p = true;
                pos_num = a.at(i);
            }else if(!found_n && a.at(i) < 0){
                found_n = true;
                neg_num = a.at(i);
            }
        }

        if(found_p && !found_n){
            nn.pop_back();
            pn.push_back(pos_num);
        }else if(!found_p && found_n){
            if(pn.size() > 0){
                pn.pop_back();
                nn.push_back(neg_num);
            }else{
                nn.clear();
                REP(i, k){
                    nn.push_back(a.at(n - 1 - i));
                }
            }
        }else if(found_p && found_n){
            if(pn.size() == 0){
                nn.pop_back();
                pn.push_back(pos_num);
            }else{
                if(pos_num * pn.back() >= abs(neg_num) * abs(nn.back())){
                    nn.pop_back();
                    pn.push_back(pos_num);
                }else{
                    pn.pop_back();
                    nn.push_back(neg_num);
                }
            }
        }
    }

    mint ans = 1;
    for(ll x : pn){ ans *= x; }
    for(ll y : nn){ ans *= y; }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6916