#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

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

    int n, k;
    cin >> n >> k;

    vs64 a(n);
    vector< pair<s64, int> > b(n);
    int cnt[3] = {0, 0, 0};
    rep (i, n)
    {
        cin >> a[i];
        if (a[i] > 0)
        {
            b[i] = make_pair(abs(a[i]), 1);
            ++cnt[0];
        }
        else if (a[i] < 0)
        {
            b[i] = make_pair(abs(a[i]), -1);
            ++cnt[1];
        }
        else
        {
            b[i] = make_pair(0, 0);
            ++cnt[2];
        }
    }

    sort(b.begin(), b.end(), greater<pair<s64, int>>());

    s64 ans = 1;
    int sign = 1;
    int num[3] = {0, 0, 0};
    rep (i, k)
    {
        ans = (ans * b[i].first) % MOD;
        sign *= b[i].second;
        if (b[i].second == 1) ++num[0];
        else if (b[i].second == -1) ++num[1];
        else ++num[2];
    }

    if (sign == 0)
    {
        ans = 0;
    }
    else if (sign < 0)
    {
        if (n == k)
        {
            ans = ans * (MOD - 1) % MOD;
        }
        else if (cnt[0] == 0)
        {
            ans = 1;
            for (int i = n - 1; i >= n - k; --i)
            {
                ans = ans * b[i].first % MOD;
            }
            ans = ans * (MOD - 1) % MOD;
        }
        else // plus number exists
        {
            // if (cnt[0] - num[0] == 1)
            // {
            //     for (int i = k - 1; i >= 0; --i)
            //     {
            //         if (b[i].second == -1)
            //         {
            //             ans = ans * mypow(b[i].first, MOD - 2);
            //             break;
            //         }
            //     }

            //     for (int i = k; i < n; ++i)
            //     {
            //         if (b[i].second == 1)
            //         {
            //             ans = ans * b[i].first % MOD;
            //             break;
            //         }
            //     }
            // }
            // if (cnt[0] - num[0] >= 1)
            {
                const s64 inf = 1000000000ll + 1;
                s64 plus[2] = {inf, 0};
                s64 minus[2] = {inf, 0};
                for (int i = k - 1; i >= 0; --i)
                {
                    if (b[i].second == 1 && plus[0] > b[i].first)
                    {
                        plus[0] = b[i].first;
                    }
                    else if (b[i].second == -1 && minus[0] > b[i].first)
                    {
                        minus[0] = b[i].first;
                    }
                }
                for (int i = k; i < n; ++i)
                {
                    if (b[i].second == 1 && plus[1] < b[i].first)
                    {
                        plus[1] = b[i].first;
                    }
                    else if (b[i].second == -1 && minus[1] < b[i].first)
                    {
                        minus[1] = b[i].first;
                    }
                }

                if (plus[0] == inf)
                {
                    ans = ans * mypow(minus[0], MOD - 2) % MOD * plus[1] % MOD;
                }
                else if (minus[0] == inf)
                {
                    ans = ans * mypow(plus[0], MOD - 2) % MOD * minus[1] % MOD;
                }
                else if (plus[0] * plus[1] > minus[0] * minus[1])
                {
                    ans = ans * mypow(minus[0], MOD - 2) % MOD * plus[1] % MOD;
                }
                else
                {
                    ans = ans * mypow(plus[0], MOD - 2) % MOD * minus[1] % MOD;
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 7856