#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion

struct ModInt {
    static ll mod;
    ll val;
    ModInt(ll v = 0) : val(v % mod) {}
    ModInt operator-() const { return ModInt(val ? mod - val : val); }
    ModInt &operator+=(ModInt a) {
        if ((val += a.val) >= mod) val -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt a) {
        if ((val -= a.val) < 0) val += mod;
        return *this;
    }
    ModInt &operator*=(ModInt a) {
        val = (__uint128_t(val) * a.val) % mod;
        return *this;
    }
    ModInt &operator/=(ModInt a) {
        ll u = 1, v = a.val, s = 0, t = mod;
        while (v) {
            ll q = t / v;
            swap(s -= u * q, u);
            swap(t -= v * q, v);
        }
        a.val = (s < 0 ? s + mod : s);
        val /= t;
        return (*this) *= a;
    }
    ModInt inv() const { return ModInt(1) /= (*this); }
    bool operator<(ModInt x) const { return val < x.val; }
};
ll ModInt::mod = 1e9 + 7;

ostream &operator<<(ostream &os, ModInt a) {
    os << a.val;
    return os;
}
ModInt operator+(ModInt a, ModInt b) { return a += b; }
ModInt operator-(ModInt a, ModInt b) { return a -= b; }
ModInt operator*(ModInt a, ModInt b) { return a *= b; }
ModInt operator/(ModInt a, ModInt b) { return a /= b; }
ModInt pow(ModInt a, ll e) {
    ModInt x(1);
    for (; e > 0; e /= 2) {
        if (e % 2 == 1) x *= a;
        a *= a;
    }
    return x;
}

ModInt comb(int n, int k) {
    ModInt x = 1, y = 1;
    rep(i, k) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    cin >> a;

    if (n == k) {
        int cnt_naga = 0;
        rep(i, n) if (a[i] < 0) cnt_naga++;
        ModInt ans = 1;
        rep(i, k) ans *= a[i] < 0 ? -a[i] : a[i];
        if (cnt_naga % 2 == 1) {
            ll ans2 = ans.val;
            cout << -ans2 + ll(1e9 + 7) << endl;
        }
        else cout << ans << endl;
        return 0;
    }

    sort(a.begin(), a.end());
    if (a.back() < 0 && k % 2 == 1) { // 全部負でkが奇数
        ModInt ans = 1;
        reverse(a.begin(), a.end());
        rep(i, k) ans *= -a[i];
        ll ans2 = ans.val;
        if (k % 2 == 1) ans2 *= -1;
        cout << ans2 + ll((1e9) + 7) << endl;
        return 0;
    }

    // n > k
    vector<ll> nega, posi;
    rep(i, n) {
        if (0 <= a[i]) posi.push_back(a[i]);
        else nega.push_back(-a[i]);
    }

    // 絶対値大きい順
    sort(nega.rbegin(), nega.rend());
    sort(posi.rbegin(), posi.rend());

    int ns = nega.size(), ps = posi.size();
    int max_pick_nega = min(ns - ns % 2, k - k % 2);

    ModInt now = 1;
    rep(i, max_pick_nega) now *= nega[i];
    rep(i, k - max_pick_nega) now *= posi[i];

    int ni = max_pick_nega - 1;
    for (int pi = k - max_pick_nega; pi < ps; pi += 2) {
        //cout << pi << endl;
        if (ps <= pi + 1) break;
        if (ni <= 0) break;

        if (nega[ni] * nega[ni - 1] <= posi[pi] * posi[pi + 1]) {
            now /= nega[ni] * nega[ni - 1];
            ni -= 2;
            now *= posi[pi] * posi[pi + 1];
        }
        else break;
    }

    cout << now << endl;
}

Measured memory_bytes: 7048