//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

//--------------------------- Solve ---------------------------//

void solve() {
    int N, K; cin >> N >> K;
    vector<long long> A(N), plus, minus;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] >= 0) plus.push_back(A[i]);
        else minus.push_back(A[i]);
    }

    sort(plus.begin(), plus.end());
    sort(minus.rbegin(), minus.rend());
    sort(A.begin(), A.end(), [](int x, int y) { return abs(x) < abs(y); } );

    bool ok;
    if (plus.size()) {
        if (N == K) {
            if (minus.size() % 2 == 0) ok = true;
            else ok = false;
        }
        else ok = true;
    }
    else {
        if (K % 2 == 0) ok = true;
        else ok = false;
    }

    mint ans = 1;
    if (ok) {
        if (K % 2 == 1) {
            ans *= plus.back();
            plus.pop_back();
            K--;         
        }
        vector<long long> v;
        while (plus.size() >= 2) {
            long long x = plus.back(); plus.pop_back();
            long long y = plus.back(); plus.pop_back();
            v.push_back(x*y);
        }
        while (minus.size() >= 2) {
            long long x = minus.back(); minus.pop_back();
            long long y = minus.back(); minus.pop_back();
            v.push_back(x*y);
        }
        sort(v.rbegin(), v.rend());
        for (int i = 0; i < K/2; i++) ans *= v[i];
    }
    else {
        for (int i = 0; i < K; i++) ans *= A[i];
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 8140