#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

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

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

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

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n, k;
    cin >> n >> k;
    bool pos = false;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        if (a[i] >= 0) pos = true;
    }
    Mint<> ans = 1;
    if (n == k) {
        rep(i, k) {
            ans *= a[i];
        }
        cout << ans << endl;
        return 0;
    }
    if (!pos && k % 2) {
        sort(a, a + n);
        reverse(a, a + n);
        rep(i, k) {
            ans *= a[i];
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> vp, vn;
    rep(i, n) {
        if (a[i] >= 0)
            vp.emplace_back(a[i]);
        else
            vn.emplace_back(a[i]);
    }
    sort(ALL(vp));
    reverse(ALL(vp));
    sort(ALL(vn));
    int ppos = 0, npos = 0;
    while (k > 0) {
        if (k == 1) {
            ans *= vp[ppos];
            break;
        }
        if ((ppos + 1 >= (int)vp.size()) ||
            (npos + 1 < (int)vn.size() &&
             vn[npos] * vn[npos + 1] >= vp[ppos] * vp[ppos + 1])) {
            ans *= vn[npos];
            ans *= vn[npos + 1];
            npos += 2;
            k -= 2;
        } else {
            ans *= vp[ppos];
            ppos++;
            k--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6896