#include <bits/stdc++.h>


using namespace std;


using ll = long long;


template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};

const long long M = 1000000007;

using mint = modint<M>;


int main(void) {
    ll N, K;

    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll num_negative = 0;
    for (auto e : A) {
        if (e < 0) {
            num_negative++;
        }
    }

    bool is_positive;
    if (N == K) {
        is_positive = (num_negative % 2 == 0);
    } else if (N > K) {
        if (num_negative == N) {
            is_positive = (K % 2 == 0);
        } else {
            is_positive = true;
        }
    }

    mint ans(1);
    if (!is_positive) {
        sort(A.begin(), A.end(), [](auto &x, auto &y) {
                return abs(x) < abs(y);
                });
        for (ll i = 0; i < K; i++) {
            ans = (ans * mint(A[i]));
        }
    } else {
        vector<ll> positive, negative;
        for (auto e : A) {
            if (e >= 0) {
                positive.push_back(e);
            } else {
                negative.push_back(e);
            }
        }
        sort(positive.begin(), positive.end());
        sort(negative.rbegin(), negative.rend());

        vector<ll> p;
        if (K % 2 == 1) {
            ans = ans * mint(positive.back());
            positive.pop_back();
        }

        for (auto it = positive.rbegin(); it < positive.rend(); it += 2) {
            p.push_back(*it * *(it + 1));
        }
        for (auto it = negative.rbegin(); it < negative.rend(); it += 2) {
            p.push_back(*it * *(it + 1));
        }
        sort(p.rbegin(), p.rend());

        for (ll i = 0; i < K / 2; i++) {
            ans = ans * mint(p[i]);
        }
    }

    cout << ans.a << endl;
}


Measured memory_bytes: 8164