#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
#include <cstdint>
template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while(exp) {
            if(exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
using mint = modint<MOD>;
void input() {
    cin >> n >> k;
    rep(i, n) {
        cin >> x;
        if(x > 0)
            A.pb(x);
        else
            B.pb(x);
    }
}
void solve() {
    sort(all(A));
    reverse(all(A));
    sort(all(B));
    mint ans = 1;
    if(n == k) {
        for(ll i : A) {
            ans *= i;
        }
        for(ll i : B) {
            ans *= abs(i);
        }
        if(B.size() % 2 == 1)
            ans = mint(0) - ans;
        print(ans.a);
        return;
    }
    if(k % 2 == 1 && A.size() == 0) {
        reverse(all(B));
        rep(i, k) { ans *= abs(B[i]); }
        ans = mint(0) - ans;
        print(ans.a);
        return;
    }
    if(k % 2 == 0 && A.size() == 0) {
        rep(i, k) { ans *= abs(B[i]); }
        print(ans.a);
        return;
    }
    a = 0;
    b = 0;
    while(k) {
        if(k == 1) {
        iti:
            ans *= A[a];
            a++;
            k--;
        } else {
            if(a + 1 >= A.size()) {
                ans *= abs(B[b]);
                ans *= abs(B[b + 1]);
                b += 2;
                k -= 2;
                continue;
            }
            if(b + 1 >= B.size()) {
                goto iti;
            }
            x = A[a] * A[a + 1];
            y = B[b] * B[b + 1];
            if(x > y) {
                ans *= A[a];
                ans *= A[a + 1];
                a += 2;
                k -= 2;
                continue;
            } else {
                ans *= abs(B[b]);
                ans *= abs(B[b + 1]);
                b += 2;
                k -= 2;
                continue;
            }
        }
    }
    print(ans.a);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 5600