#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

ll modinv(ll a) {
    ll m = mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n, k;
    cin >> n >> k;
    int z = 0;
    int po = 0, ne = 0;
    vector<P> v;
    for (i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a == 0)
            z++;
        else if (a > 0) {
            v.pb(P(a, 1));
            po++;
        } else {
            v.pb(P(-a, -1));
            ne++;
        }
    }
    sort(v.begin(), v.end());
    if (po == 0) {
        if (k % 2 == 0) {
            reverse(v.begin(), v.end());
            if (ne < k) {
                cout << 0 << endl;
                return 0;
            }
            ll ans = 1;
            for (i = 0; i < k; i++) {
                ans *= v[i].fi;
                ans %= mod;
            }
            cout << ans << endl;
            return 0;
        } else {
            if (z > 0) {
                cout << 0 << endl;
                return 0;
            }
            ll ans = 1;
            for (i = 0; i < k; i++) {
                ans *= v[i].fi;
                ans %= mod;
            }
            cout << mod - ans << endl;
            return 0;
        }
    }

    if (po + ne / 2 * 2 >= k) {
        reverse(v.begin(), v.end());
        bool f = 1;
        ll ans = 1;
        ll pm = -1;
        ll nm = -1;
        for (i = 0; i < k; i++) {
            ans *= v[i].fi;
            ans %= mod;
            if (v[i].se == 1) {
                pm = v[i].fi;
            } else {
                nm = v[i].fi;
                f = !f;
            }
        }
        if (f) {
            cout << ans << endl;
            return 0;
        } else {
            if (pm == -1) {
                ans *= modinv(nm);
                ans %= mod;
                for (i = k; i < v.size(); i++) {
                    if (v[i].se == 1) {
                        ans *= v[i].fi;
                        ans %= mod;
                        cout << ans << endl;
                        return 0;
                    }
                }
            }
            ll nnm = -1;
            ll npm = -1;
            for (i = k; i < v.size(); i++) {
                if (v[i].se == 1) {
                    if (npm == -1) npm = v[i].fi;
                } else {
                    if (nnm == -1) nnm = v[i].fi;
                }
            }
            if (npm == -1) {
                ans *= modinv(pm);
                ans %= mod;
                ans *= nnm;
                ans %= mod;
                cout << ans << endl;
                return 0;
            }
            if (nnm == -1) {
                ans *= modinv(nm);
                ans %= mod;
                ans *= npm;
                ans %= mod;
                cout << ans << endl;
                return 0;
            }
            if (npm * pm > nnm * nm) {
                ans *= modinv(nm);
                ans %= mod;
                ans *= npm;
                ans %= mod;
                cout << ans << endl;
                return 0;
            } else {
                ans *= modinv(pm);
                ans %= mod;
                ans *= nnm;
                ans %= mod;
                cout << ans << endl;
                return 0;
            }
        }
    } else if (z > 0) {
        cout << 0 << endl;
        return 0;
    } else {
        ll ans = 1;
        for (i = 0; i < k; i++) {
            ans *= v[i].fi;
            ans %= mod;
        }
        cout << mod - ans << endl;
    }
}

Measured memory_bytes: 7280