#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n, k;
ll a[N];
ll ans = 1;
ll b[N], c[N];
int c1, c2;
int m;
ll choosed[N];

void solve()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] >= 0)
            b[++c1] = a[i];
        else
            c[++c2] = a[i];
    }
    sort(b + 1, b + c1 + 1, greater<ll>());
    sort(c + 1, c + c2 + 1);
    if (c1 == 0)
    {
        int cnt = 0;
        if (k & 1)
        {
            for (int i = c2; i >= 1; --i)
            {
                cnt++;
                ans *= c[i];
                ans %= mod;
                // ans += mod, ans %= mod;
                if (cnt == k)
                    break;
            }
        }
        else
        {
            for (int i = 1; i <= c2; ++i)
            {
                cnt++;
                ans *= abs(c[i]);
                ans %= mod;
                // ans += mod, ans %= mod;
                if (cnt == k)
                    break;
            }
        }
        ans += mod, ans %= mod;
        cout << ans;
        return;
    }
    int l1 = 1, l2 = 1;
    while (l1 + l2 < k + 2)
    {
        ll num;
        if (abs(c[l2]) >= b[l1] && l2 <= c2 && l1 <= c1)
            num = c[l2], l2++;
        else if (l2 > c2 && l1 <= c1)
            num = b[l1], l1++;
        else if (l1 > c1 && l2 <= c2)
            num = c[l2], l2++;
        else if (abs(c[l2]) < b[l1] && l2 <= c2 && l1 <= c1)
            num = b[l1], l1++;
        choosed[++m] = num;
    }
    if (l2 % 2 == 0)
    {
        if (b[l1] * b[l1 - 1] <= abs(c[l2 - 1]) * abs(c[l2]) && l2 <= c2 && l1 <= c1 && l1 > 1 && l2 > 1)
        {
            for (int i = 1; i <= m; ++i)
            {
                if (choosed[i] == b[l1 - 1])
                {
                    choosed[i] = c[l2];
                    break;
                }
            }
        }
        else if (b[l1] * b[l1 - 1] > abs(c[l2 - 1]) * abs(c[l2]) && l1 <= c1 && l2 <= c2 && l1 > 1 && l2 > 1)
        {
            for (int i = 1; i <= m; ++i)
            {
                if (choosed[i] == c[l2 - 1])
                {
                    choosed[i] = b[l1];
                    break;
                }
            }
        }
        else if (l1 > c1 && l2 <= c2)
        {
            for (int i = 1; i <= m; ++i)
            {
                if (choosed[i] == b[l1 - 1])
                {
                    choosed[i] = c[l2];
                    break;
                }
            }
        }
        else if (l2 > c2 && l1 <= c1)
        {
            for (int i = 1; i <= m; ++i)
            {
                if (choosed[i] == c[l2 - 1])
                {
                    choosed[i] = b[l1];
                    break;
                }
            }
        }
        else if(l1 == 1)
        {
            for (int i = 1; i <= n;++i)
            {
                if(choosed[i] == c[l2-1])
                {
                    choosed[i] = b[l1];
                    break;
                }
            }
        }
    }
    int fu = 0;
    for (int i = 1; i <= m; ++i)
    {
        if (choosed[i] < 0)
            fu++;
    }
    if (fu % 2 == 0)
    {
        for (int i = 1; i <= m; ++i)
        {
            ans *= abs(choosed[i]);
            ans %= mod;
        }
    }
    else
    {
        for (int i = 1; i <= m; ++i)
        {
            ans *= choosed[i];
            ans %= mod;
            ans += mod, ans %= mod;
        }
    }
    ans += mod, ans %= mod;
    cout << ans;
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 8324