#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
struct modint {
    ll x;
    modint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    ll value() const {
        return x;
    }
    modint operator-() const {
        return modint(-x);
    }
    modint& operator+=(const modint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator-=(const modint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator*=(const modint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    modint operator+(const modint a) const {
        modint res(*this);
        return res += a;
    }
    modint operator-(const modint a) const {
        modint res(*this);
        return res -= a;
    }
    modint operator*(const modint a) const {
        modint res(*this);
        return res *= a;
    }
    modint pow(ll t) const {
        if (t == 0) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t % 2 == 1) a *= *this;
        return a;
    }
    modint inv() const {
        return pow(MOD - 2);
    }
    modint& operator/=(const modint a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint a) const {
        modint res(*this);
        return res /= a;
    }
};
ostream& operator<<(ostream& os, const modint& x) {
    os << x.value();
    return os;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    if ((k & 1) && (*max_element(all(a)) <= 0ll)) {
        modint ans = 1;
        sort(all(a), greater<ll>());
        rep(i, k) ans *= a[i];
        cout << ans << endl;
        return 0;
    }
    sort(all(a), [](ll x, ll y) { return abs(x) > abs(y); });
    modint ans = 1;
    bool fin = 0;
    rep(i, k) ans *= a[i], fin |= a[i] == 0;
    if (k == n) {
        cout << ans << endl;
        return 0;
    }
    if (fin) {
        cout << 0 << endl;
        return 0;
    }
    int cnt = 0;
    rep(i, k) cnt += (a[i] < 0);
    if (cnt % 2 == 0) {
        cout << ans << endl;
        return 0;
    }

    if (a[k] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll x1 = LINF, x2 = LINF, y1 = LINF, y2 = LINF;
    rrep(i, k) {
        if (a[i] < 0ll) {
            x1 = a[i];
            break;
        }
    }
    rrep(i, k) {
        if (a[i] > 0ll) {
            y1 = a[i];
            break;
        }
    }
    for (int i = k; i < n; i++) {
        if (a[i] < 0ll) {
            y2 = a[i];
            break;
        }
    }
    for (int i = k; i < n; i++) {
        if (a[i] > 0ll) {
            x2 = a[i];
            break;
        }
    }

    if (x1 != LINF && x2 != LINF &&
        (y1 == LINF || y2 == LINF || abs(x2 * y1) > abs(x1 * y2))) {
        ans *= modint(x2);
        ans /= modint(x1);
        cout << ans << endl;
        return 0;
    }
    if (y1 != LINF && y2 != LINF &&
        (x1 == LINF || x2 == LINF || abs(x2 * y1) <= abs(x1 * y2))) {
        ans *= modint(y2);
        ans /= modint(y1);
        cout << ans << endl;
        return 0;
    }

    assert(1);
}

Measured memory_bytes: 4836