#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

constexpr int MOD = 1'000'000'007;

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return ModInt(a);
    }
    friend std::ostream &operator<<(std::ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend std::istream &operator>>(std::istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
	int n, k;
	std::cin >> n >> k;
    std::deque<long long> a, b;
    {
        std::vector<long long> s, t;
        for (int e, i = 0; i < n; i++) {
            std::cin >> e;
            if (e < 0) s.push_back(e);
            else t.push_back(e);
        }
        std::sort(s.begin(), s.end());
        std::sort(t.begin(), t.end(), std::greater<>());
        for (auto e : s) a.push_back(e);
        for (auto e : t) b.push_back(e);
    }

    ModInt<MOD> ans = 1;

    if (n == k) {
        for (auto e : a) ans *= e;
        for (auto e : b) ans *= e;
        std::cout << ans << '\n';
        return 0;
    }
    if ((k & 1) and not b.size()) {
        for (int i = 0; i < k; i++) {
            ans *= a.back();
            a.pop_back();
        }
        std::cout << ans << '\n';
        return 0;
    }

    if (k & 1) {
        k--;
        ans *= b.front();
        b.pop_front();
    }

    while (k > 0) {
        k -= 2;
        if (a.size() > 1 and b.size() > 1) {
            long long aa = a[0] * a[1];
            long long bb = b[0] * b[1];
            if (aa > bb) {
                ans *= aa;
                a.pop_front();
                a.pop_front();
            } else {
                ans *= bb;
                b.pop_front();
                b.pop_front();
            }
        } else if (a.size() > 1) {
            long long aa = a[0] * a[1];
            ans *= aa;
            a.pop_front();
            a.pop_front();
        } else {
            long long bb = b[0] * b[1];
            ans *= bb;
            b.pop_front();
            b.pop_front();
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 6368