#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b)
{
    if (a < b)
    {
        a = b;
    }
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b)
{
    if (a > b)
    {
        a = b;
    }
}

constexpr ll mod = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<pair<uint64_t, bool>> V(N);
    ll cnt_p = 0;
    ll cnt_m = 0;

    rep(i, N)
    {
        ll num;
        cin >> num;
        if (num > 0)
        {
            V[i] = make_pair(num, true);
            ++cnt_p;
        }
        else
        {
            V[i] = make_pair(abs(num), false);
            ++cnt_m;
        }
    }

    ll ans = 1;
    if ((N == K && cnt_m % 2 == 1) || (cnt_p == 0 && K % 2 == 1))
    {
        sort(all(V));
        rep(i, K)
        {
            ans *= V[i].first % mod;
            ans %= mod;
        }
        if (ans == 0)
        {
            ans = 0;
        }
        else
        {
            ans = -ans + mod;
        }
    }
    else
    {
        sort(all(V), greater<pair<uint64_t, bool>>());
        ll fugou = 1;
        ll last_p = -1;
        ll last_m = -1;
        rep(i, K)
        {
            if (V[i].second)
            {
                last_p = i;
            }
            else
            {
                last_m = i;
                fugou *= -1;
            }
        }

        if (fugou == 1)
        {
            rep(i, K)
            {
                ans *= V[i].first % mod;
                ans %= mod;
            }
        }
        else
        {
            ll next_p = -1;
            ll next_m = -1;
            for (ll i = K; i < N; ++i)
            {
                if (V[i].second == true)
                {
                    next_p = i;
                    break;
                }
            }
            for (ll i = K; i < N; ++i)
            {
                if (V[i].second == false)
                {
                    next_m = i;
                    break;
                }
            }

            ll id_ex = -1;
            ll id_in = -1;
            if (last_p != -1 && last_m != -1 && next_p != -1 && next_m != -1)
            {
                if (V[last_m].first * V[next_m].first >= V[last_p].first * V[next_p].first)
                {
                    id_ex = last_p;
                    id_in = next_m;
                }
                else
                {
                    id_ex = last_m;
                    id_in = next_p;
                }
            }
            else if (last_p == -1 || next_m == -1)
            {
                id_ex = last_m;
                id_in = next_p;
            }
            else if (last_m == -1 || next_p == -1)
            {
                id_ex = last_p;
                id_in = next_m;
            }

            rep(i, K)
            {
                if (i == id_ex)
                {
                    continue;
                }
                ans *= V[i].first % mod;
                ans %= mod;
            }
            ans *= V[id_in].first % mod;
            ans %= mod;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6432