#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;
    vec A(N);
    ll plus = 0, zero = 0, minus = 0;
    vec nplus, nminus;
    Rep (i, N) {
        cin >> A[i];
        if (A[i] > 0) {
            plus++;
            nplus.push_back(A[i]);
        }
        else if (A[i] == 0) zero++;
        else {
            minus++;
            nminus.push_back(A[i]);
        }
    }

    sort(A.begin(), A.end(), [](ll a, ll b){
        if (abs(a) == abs(b)) return a < b;
        else return abs(a) < abs(b);
    });
    reverse(A.begin(), A.end());

    mint ans(1);
    ll cnt = 0;
    ll idx = -1, midx = -1;
    Rep (i, K) {
        ans *= A[i];
        if (A[i] < 0) {
            cnt++;
            midx = i;
        } else if (A[i] > 0) {
            idx = i;
        }
    }

    if (cnt % 2) {
        // cout << idx << "\n";
        ll now = K;

        if (idx == -1) {
            idx = K-1;
            for (; now < N; now++) {
                // cout << now << "\n";
                if (A[now] > 0) {
                    break;
                }
            }
            // printvec(A);
            // cout << idx << " " << now << "\n";

            if (now < N) {
                ans *= mint(A[idx]).inv();
                ans *= mint(A[now]);
            } else {
                ans = mint(1);
                reverse(A.begin(), A.end());
                // printvec(A);
                Rep (i, K) {
                    ans *= A[i];
                }
            }

        } else {
            ll idx2 = -1;
            ll midx2 = -1;

            for (; now < N; now++) {
                if (A[now] < 0 and midx2 < 0) midx2 = now;
                else if (A[now] > 0 and idx2 < 0) idx2 = now;
            }

            // printvec(A);
            // cout << idx << " " << now << "\n";
            if (idx2 != -1 and midx2 != -1) {
                if (A[midx] * A[midx2] < A[idx] * A[idx2]) {
                    ans *= mint(A[midx]).inv();
                    ans *= mint(A[idx2]);
                } else {
                    ans *= mint(A[idx]).inv();
                    ans *= mint(A[midx2]);
                }
            } else if (idx2 != -1) {
                ans *= mint(A[midx]).inv();
                ans *= mint(A[idx2]);
            } else if (midx2 != -1) {
                ans *= mint(A[idx]).inv();
                ans *= mint(A[midx2]);
            } else {
                ans = mint(1);
                reverse(A.begin(), A.end());
                // printvec(A);
                Rep (i, K) {
                    ans *= A[i];
                }
            }
        }
    }

    cout << ans << endl;    
}

Measured memory_bytes: 6976