#include <bits/stdc++.h>
using namespace std;

template<int64_t MOD> class ModInt {
public:
    int64_t x;
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t v) : x((v % MOD + MOD) % MOD) {}
    constexpr ModInt operator - () const noexcept { return x ? MOD - x : 0;}
    constexpr ModInt operator + (const ModInt a) const noexcept { return ModInt(*this) += a;}
    constexpr ModInt operator - (const ModInt a) const noexcept { return ModInt(*this) -= a;}
    constexpr ModInt operator * (const ModInt a) const noexcept { return ModInt(*this) *= a;}
    constexpr ModInt operator / (const ModInt a) const noexcept { return ModInt(*this) /= a;}
    constexpr ModInt operator / (const int64_t a) const noexcept { return ModInt(*this) /= a;}
    constexpr ModInt operator += (const ModInt a) noexcept {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    constexpr ModInt operator += (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) += hs;
        return *this;
    }
    constexpr ModInt operator -= (const ModInt a) noexcept {
        if (x < a.x) x += MOD;
        x -= a.x;
        return *this;
    }
    constexpr ModInt operator -= (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) -= hs;
        return *this;
    }
    constexpr ModInt operator *= (const ModInt a) noexcept {
        x = x * a.x % MOD;
        return *this;
    }
    constexpr ModInt operator *= (const int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) *= hs;
        return *this;
    }
    constexpr ModInt &operator /= (ModInt a) noexcept {
        int64_t exp = MOD - 2;
        while (exp > 0) {
            if (exp & 1ul) *this *= a;
            a *= a;
            exp >>= 1ul;
        }
        return *this;
    }
    constexpr ModInt &operator /= (int64_t a) noexcept {
        auto hs = ModInt<MOD>(a);
        (*this) /= hs;
        return *this;
    }
    constexpr ModInt &operator ++ () noexcept {
        return *this;
    }
    constexpr ModInt operator ++ (int) noexcept {
        if (++x >= MOD) x -= MOD;
        return *this;
    }
    constexpr ModInt &operator -- () noexcept {
        return *this;
    }
    constexpr ModInt operator -- (int) noexcept {
        if (x-- == 0) x += MOD;
        return *this;
    }
    constexpr bool operator < (const ModInt a) const noexcept { return x < a.x;}
    constexpr bool operator == (const ModInt a) const noexcept { return this->x == a.x;}
    constexpr bool operator != (const ModInt a) const noexcept { return !(*this == a);}
    friend istream &operator >> (istream &in, ModInt &m) {
        in >> m.x;
        if (m.x < 0) m.x += MOD;
        m.x %= MOD;
        return in;
    }
    friend ostream &operator << (ostream &out, const ModInt &p) { return out << p.x;}
    constexpr ModInt pow(int64_t p) const {
        ModInt ret(1);
        ModInt mul(x);
        while (p > 0) {
            if (p & 1ul) ret *= mul;
            mul *= mul;
            p >>= 1ul;
        }
        return ret;
    }
};

const int64_t MOD = 1000000007LL;
using mint = ModInt<MOD>;

bool allMinus(const vector<int64_t> &v) {
    for(auto &e : v) {
        if(e >= 0) return false;
    }
    return true;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<int64_t> A(N), minus, plus;
    for(auto &e : A) cin >> e;
    for(auto &e : A) {
        if(e < 0) minus.push_back(e);
        else plus.push_back(e);
    }

    mint ans = 1;

    if(N == K) {
        for(auto &e : A) ans *= e;
        cout << ans << '\n';
        return 0;
    }

    if(allMinus(A)) {
        if(K % 2) sort(A.rbegin(), A.rend());
        else sort(A.begin(), A.end());
        for(int i = 0; i < K; ++i) ans *= A[i];
        cout << ans << '\n';
        return 0;
    }

    sort(minus.rbegin(), minus.rend());
    sort(plus.begin(), plus.end());

    if(K % 2) {
        ans *= plus.back();
        plus.pop_back();
        K--;
    }

    priority_queue<int64_t> que;
    while(plus.size() >= 2) {
        int lst = plus.size() - 1;
        que.push(plus[lst] * plus[lst - 1]);
        plus.pop_back();
        plus.pop_back();
    }
    while(minus.size() >= 2) {
        int lst = minus.size() - 1;
        que.push(minus[lst] * minus[lst - 1]);
        minus.pop_back();
        minus.pop_back();
    }
  
    K /= 2;
    while(K--) {
        ans *= que.top();
        que.pop();
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8200