#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

template <long long mod>
struct modular {
    long long value;
    modular(long long x = 0LL) {
        value = x % mod;
        if (value < 0LL) value += mod;
    }
    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0LL) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        long long a = 0LL, b = 1, c = other.value, m = mod;
        while (c != 0LL) {
            long long t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        a %= mod;
        if (a < 0LL) a += mod;
        value = value * a % mod;
        return *this;
    }
    modular operator-() { return modular(-value); }
    modular operator+(modular rhs) { return modular(*this) += rhs; }
    modular operator-(modular rhs) { return modular(*this) -= rhs; }
    modular operator*(modular rhs) { return modular(*this) *= rhs; }
    modular operator/(modular rhs) { return modular(*this) /= rhs; }
    bool operator==(modular rhs) { return value == rhs.value; }
    bool operator!=(modular rhs) { return value != rhs.value; }
    bool operator<(modular rhs) { return value < rhs.value; }
};
template <long long mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <long long mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    x.value %= mod;
    if (x.value < 0LL) x.value += mod;
    return stream << x.value;
}
template <long long mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0LL) x.value += mod;
    return stream;
};
const long long mod = (long long)1e9 + 7;
using mint = modular<mod>;

inline mint pw(mint a, long long n) {
    mint res = 1;
    while (n > 0LL) {
        if (n & 1) {
            res *= a;
        }
        a *= a;
        n >>= 1;
    }
    return res;
}
vector<mint> fact, finv;
inline void cinit(int n) {
    fact.resize(n, 1);
    finv.resize(n, 1);
    for (int i = 2; i < n; i++) {
        fact[i] = fact[i - 1] * i;
    }
    finv[n - 1] /= fact[n - 1];
    for (int i = n - 2; i >= 2; i--) {
        finv[i] = finv[i + 1] * (i + 1);
    }
}
inline mint C(int n, int k) {
    if (n < k || k < 0 || n < 0) {
        return mint(0LL);
    }
    return fact[n] * finv[k] * finv[n - k];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> x, y;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a > 0) {
            x.emplace_back(a);
        }
        if (a < 0) {
            y.emplace_back(-a);
        }
    }
    sort(x.rbegin(), x.rend());
    sort(y.rbegin(), y.rend());
    if (x.size() + y.size() < k) {
        cout << 0 << '\n';
        return 0;
    }
    if (x.size() == 0) {
        if (k % 2 == 1) {
            if (y.size() != n) {
                cout << 0 << '\n';
            } else {
                mint ans = -1;
                for (int i = 0; i < k; i++) {
                    ans *= y[n - 1 - i];
                }
                cout << ans << '\n';
            }
        } else {
            mint ans = 1;
            for (int i = 0; i < k; i++) {
                ans *= y[i];
            }
            cout << ans << '\n';
        }
        return 0;
    }
    if (y.size() == 0) {
        mint ans = 1;
        for (int i = 0; i < k; i++) {
            ans *= x[i];
        }
        cout << ans << '\n';
        return 0;
    }
    x.emplace_back(0);
    y.emplace_back(0);
    int xid = 0, yid = 0;
    mint ans = 1;
    while (xid + yid < k) {
        if (x[xid] >= y[yid]) {
            ans *= x[xid];
            xid++;
        } else {
            ans *= y[yid];
            yid++;
        }
    }
    if (yid % 2 == 0) {
        cout << ans << '\n';
        return 0;
    }
    if (x.size() + y.size() == k + 2) {
        cout << -ans << '\n';
        return 0;
    }
    debug(ans);
    if (xid == 0) {
        ans *= x[0];
        ans /= y[yid - 1];
        cout << ans << '\n';
        return 0;
    }
    xid--, yid--;
    ans /= x[xid];
    ans /= y[yid];
    ll a = x[xid] * x[xid + 1], b = y[yid] * y[yid + 1];
    ans *= max(a, b);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5588