#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

template <lint mod>
struct modint {
    lint v;
    constexpr modint(lint t = 0) noexcept {
        v = t % mod;
        if (v < 0)
            v += mod;
    }
    constexpr modint pow(lint k) const {
        modint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static modint add_identity() { return modint(0); }
    static modint mul_identity() { return modint(1); }
    constexpr modint inv() const { return pow(mod - 2); }

    constexpr modint &operator+=(const modint a) noexcept {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint a) noexcept {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint a) noexcept {
        v = v * a.v % mod;
        return *this;
    }
    constexpr modint &operator/=(const modint a) noexcept { return (*this) *= a.inv(); }

    constexpr modint operator+(const modint a) const noexcept { return modint(v) += a; };
    constexpr modint operator-(const modint a) const noexcept { return modint(v) -= a; };
    constexpr modint operator*(const modint a) const noexcept { return modint(v) *= a; };
    constexpr modint operator/(const modint a) const noexcept { return modint(v) /= a; };
    constexpr modint operator-() const noexcept { return v ? modint(mod - v) : modint(v); }

    constexpr bool operator==(const modint a) const noexcept { return v == a.v; }
    constexpr bool operator!=(const modint a) const noexcept { return v != a.v; }
    constexpr bool operator<(const modint a) const noexcept { return v < a.v; }
};
using mint = modint<mod>;
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n);
    deque<lint> pos, neg;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] >= 0)
            pos.push_back(a[i]);
        else
            neg.push_back(-a[i]);
    }
    if (n == k) {
        mint ret = 1;
        for (int i = 0; i < n; ++i) {
            ret *= mint(a[i]);
        }
        cout << ret << "\n";
        return 0;
    }
    sort(pos.begin(), pos.end(), greater<>());
    sort(neg.begin(), neg.end());
    if (k % 2 == 1 && pos.size() == 0) {
        mint ret = 1;
        for (int j = 0; j < k; ++j) {
            ret *= neg[j];
        }
        cout << -ret << "\n";
        return 0;
    }

    sort(neg.begin(), neg.end(), greater<>());
    mint ret = 1;
    if (k % 2 == 1) {
        ret = pos.front();
        pos.pop_front();
        k--;
    }
    vector<lint> num;
    for (int i = 1; i < (int)neg.size(); i += 2) {
        num.push_back(neg[i] * neg[i - 1]);
    }
    for (int i = 1; i < (int)pos.size(); i += 2) {
        num.push_back(pos[i] * pos[i - 1]);
    }
    sort(num.begin(), num.end(), greater<>());
    cerr << num.size() << endl;
    for (int i = 0; i < k / 2; ++i) {
        num[i] %= mod;
        ret *= num[i];
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 7408