#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using uint = unsigned int;

const int mod = 1000000007;
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() {
    ll N, K;
    cin >> N >> K;
    vector<ll> p, m, zeros;

    rep(i, N) {
        int tmp;
        cin >> tmp;
        if (tmp > 0) p.push_back(tmp);
        if (tmp == 0) zeros.push_back(tmp);
        if (tmp < 0) m.push_back(tmp);
    }

    if ((int)p.size() + (int)m.size() < K) {
        cout << 0 << endl;
        return 0;
    }

    if ((int)p.size() + (int)m.size() == K) {
        mint ans = 1;
        rep(i, (int)p.size()) ans *= p[i];
        rep(i, (int)m.size()) ans *= m[i];
        cout << ans << endl;
        return 0;
    }

    vector<pair<ll, int>> v;
    for (int i = 0; i < (int)p.size(); i++) v.push_back(make_pair(p[i], 1));
    for (int i = 0; i < (int)m.size(); i++) v.push_back(make_pair(m[i] * -1, -1));

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int sum_m = 0;
    rep(i, K) if (v[i].second == -1) sum_m++;
    if (sum_m % 2 == 0) {
        mint ans = 1;
        rep(i, K) ans *= (v[i].first * v[i].second);
        cout << ans << endl;
        return 0;
    }
    if (p.size() == 0) {
        if (zeros.size() > 0) {
            cout << 0 << endl;
            return 0;
        } else {
            sort(m.begin(), m.end());
            reverse(m.begin(), m.end());
            mint ans = 1;
            rep(i, K) ans *= m[i];
            cout << ans << endl;
            return 0;
        }
    }
    ll p1 = 10000000000;
    ll m1 = 10000000000;
    ll p2 = 0;
    ll m2 = 0;
    for (int i = K - 1; i >= 0; i--) {
        if (v[i].second == 1) {
            p1 = v[i].first;
            break;
        }
    }
    for (int i = K - 1; i >= 0; i--) {
        if (v[i].second == -1) {
            m1 = v[i].first;
            break;
        }
    }
    
    for (int i = K; i < N; i++) {
        if (v[i].second == 1) {
            p2 = v[i].first;
            break;
        }
    }
    for (int i = K; i < N; i++) {
        if (v[i].second == -1) {
            m2 = v[i].first;
            break;
        }
    }

    //cout << p1 << " " << p2 << endl;
    //cout << m1 << " " << m2 << endl;
    if (p1 * p2 > m1 * m2) {
        mint ans = 1;
        bool b = true;
        rep(i, K) {
            if (b && v[i].first == m1 && v[i].second == -1) {
                b = false;
            } else {
                ans *= (v[i].first * v[i].second);
            }
        }
        ans *= p2;
        cout << ans << endl;
    } else {
        mint ans = 1;
        bool b = true;
        rep(i, K) {
            if (b && v[i].first == p1 && v[i].second == 1) {
                b = false;
            } else {
                ans *= (v[i].first * v[i].second);
            }
        }
        ans *= (m2 * -1);
        cout << ans << endl;
    }
        
    return 0;
}


Measured memory_bytes: 8952