#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};
template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 1000000007;
// const int mod = 998244353;
using mint = ModInt< mod >;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,k;
    cin>>n>>k;
    vector<ll> v;
    int z = 0;
    int m = 0;
    ll a;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a != 0)v.push_back(a);
        if(a == 0)z++;
        if(a < 0)m++;
    }
    if(z > n-k){
        cout << 0 << endl;
        return 0;
    }
    if(n==m+z){
        mint ans = 1;
        if(k%2){
            sort(v.begin(),v.end(),greater<ll>());
            for(int i=0;i<k;i++){
                ans *= v[i];
            }
            if(z) ans = 0;
        }
        else{
            sort(v.begin(),v.end());
            for(int i=0;i<k;i++){
                ans *= v[i];
            }
        }
        cout << ans << endl;
        return 0;
    }
    mint ans = 1;
    sort(v.begin(),v.end(),greater<ll>());
    for(int i=0;i<k;i++) ans = ans * v[i];
    int r = k-1;
    int now = v.size()-1;
    while(r>=1 && v[now-1]<0){
        ll p = v[r] * v[r-1];
        ll m = v[now] * v[now-1];
        if(p <= m){
            ans /= p;
            ans *= m;
            r-=2;
            now -= 2;
        }
        else break;
    }
    cout << ans << endl;

}

Measured memory_bytes: 5324