#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using i64 = long long;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

int main() {
    constexpr i64 mod = 1000000007;
    int n, k;
    std::cin >> n >> k;
    std::vector<i64> neg, pos;
    for (int i = 0; i < n; i++) {
        i64 in;
        std::cin >> in;
        if (in > 0) pos.push_back(in);
        else neg.push_back(in);
    }

    std::sort(pos.begin(), pos.end(), std::greater<>());
    std::sort(neg.begin(), neg.end());

    if (pos.size() == n) {
        i64 ret = 1;
        for (int i = 0; i < k; i++) ret = ret * pos[i] % mod;
        std::cout << ret << std::endl;
    } else if (neg.size() == n) {
        i64 ret = 1;
        if (k % 2) {
            for (int i = 0; i < k; i++) ret = ret * (mod + neg[n - 1 - i]) % mod;
        } else {
            for (int i = 0; i < k; i++) ret = ret * (mod + neg[i]) % mod;
        }
        std::cout << ret << std::endl;
    } else if (pos.size() + neg.size() < k) {
        std::cout << 0 << std::endl;
    } else if (pos.size() == 0) {
        if (k % 2) {
            std::cout << 0 << std::endl;
        } else {
            i64 ret = 1;
            for (int i = 0; i < k; i++) ret = ret * (mod + neg[i]) % mod;
            std::cout << ret << std::endl;
        }
    } else if (neg.size() == 0) {
        i64 ret = 1;
        for (int i = 0; i < k; i++) ret = ret * pos[i] % mod;
        std::cout << ret << std::endl;
    } else {
        const int m = pos.size() + neg.size();
        if (m == k) {
            i64 ret = 1;
            for (const i64 e : pos) ret = ret * e % mod;
            for (const i64 e : neg) ret = ret * (mod + e) % mod;
            std::cout << ret << std::endl;
        } else {
            i64 ret = 1;
            auto pt = pos.cbegin(), nt = neg.cbegin();
            for (int i = 0; i < k; i++) {
                if (nt == neg.cend() || (pt != pos.cend() && *pt > -*nt)) {
                    ret = ret * *pt++ % mod;
                } else {
                    ret = ret * (mod + *nt++) % mod;
                }
            }

            if ((nt - neg.cbegin()) % 2 == 0) {
                std::cout << ret << std::endl;
            } else if (pt == pos.cend() || nt == neg.cbegin()) {
                ret = ret * inverse(*std::prev(pt), mod) % mod * (mod + *nt) % mod;
                std::cout << ret << std::endl;
            } else if (nt == neg.cend() || pt == pos.cbegin()) {
                ret = ret * inverse((mod + *std::prev(nt)), mod) % mod * *pt % mod;
                std::cout << ret << std::endl;
            } else {
                const i64 pp = *std::prev(pt), np = *pt,
                    pn = *std::prev(nt), nn = *nt;
                if (pn * nn > pp * np) {
                    ret = ret * inverse(pp, mod) % mod * (mod + nn) % mod;
                } else {
                    ret = ret * inverse((mod + pn), mod) % mod * np % mod;
                }
                std::cout << ret << std::endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 5652