#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int sign(ll x)
{
    return (x > 0) - (x < 0);
}

int main()
{
    ll modulus = 1000000007;

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll countNevative = 0;
    rep(i, n)
    {
        if (a[i] < 0)
        {
            ++countNevative;
        }
    }
    bool resultIsNegative = false;
    if (n == k && countNevative % 2 == 1)
        resultIsNegative = true;
    if (k % 2 == 1 && countNevative == n)
    {
        resultIsNegative = true;
    }
    if (resultIsNegative)
    {
        sort(a.begin(), a.end(), [](ll x, ll y) {
            return abs(x) < abs(y);
        });

        ll result = 1;
        for (ll i = 0; i < k; ++i)
        {
            result = result * a[i] % modulus;
        }
        if (result < 0)
        {
            result += modulus;
        }
        cout << result << endl;
        return 0;
    }
    else
    {
        vector<ll> pos;
        vector<ll> neg;
        rep(i, n)
        {
            if (a[i] < 0)
            {
                neg.push_back(a[i]);
            }
            else
            {
                pos.push_back(a[i]);
            }
        }
        sort(neg.rbegin(), neg.rend()); // 末尾が絶対値でかい
        sort(pos.begin(), pos.end());   // 末尾が絶対値でかい
        ll result = 1;
        ll initial = 0;
        if (k % 2 == 1)
        {
            result = result * (*pos.rbegin()) % modulus;
            pos.pop_back();
            initial = 1;
        }
        for (ll i = initial; i < k; i += 2)
        {
            ll n2;
            ll p2;
            if (neg.size() >= 2)
            {
                n2 = (*neg.rbegin()) * (*(++neg.rbegin()));
            }
            else
            {
                n2 = LLONG_MIN;
            }
            if (pos.size() >= 2)
            {
                p2 = (*pos.rbegin()) * (*(++pos.rbegin()));
            }
            else
            {
                p2 = LLONG_MIN;
            }
            if (n2 < p2)
            {
                result = result * (*pos.rbegin()) % modulus;
                pos.pop_back();
                result = result * (*pos.rbegin()) % modulus;
                pos.pop_back();
            }
            else
            {
                result = result * (*neg.rbegin()) % modulus;
                neg.pop_back();
                result = result * (*neg.rbegin()) % modulus;
                neg.pop_back();
            }
        }
        if (result < 0)
        {
            result += modulus;
        }
        cout << result << endl;
        return 0;
    }
}

Measured memory_bytes: 6492