#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
//#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define N 500500
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = (ll)1e9 + 7;


int n, k;
ll a[N];
pair<ll, ll> b[N];

ll binpow (ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return (binpow (a, n-1) * a) % mod;
    else {
        ll b = binpow (a, n/2);
        return (b * b) % mod;
    }
}

void solve() {
    cin >> n >> k;
    vector<int> A, B, Z;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = {abs(a[i]), i};
        if (a[i] > 0) A.emplace_back(i);
        if (a[i] < 0) B.emplace_back(i);
        if (a[i] == 0) Z.emplace_back(i);
    }

    if (k > (int)A.size() + (int)B.size()) {
        cout << 0 << "\n";
        return;
    }

    if (k == (int)A.size() + (int)B.size()) {
        ll ans = 1;
        for (int i = 1; i <= n; ++i) {
            ll mul = ((a[i] % mod) + mod) % mod;
            ans = (ans * mul) % mod;
        }
        cout << ans << "\n";
        return;
    }

    if (A.empty()) {
        sort(a + 1, a + n + 1);
        if (k % 2 == 1)
            reverse(a + 1, a + n + 1);

        ll ans = 1;
        for (int i = 1; i <= k; ++i) {
            ll mul = ((a[i] % mod) + mod) % mod;
            ans = (ans * mul) % mod;
        }
        cout << ans << "\n";
        return;
    }

    sort(b + 1, b + n + 1);
    reverse(b + 1, b + n + 1);

    int odd = 0;
    for (int i = 1; i <= k; ++i) if (a[b[i].second] < 0) ++odd;

    if (odd % 2 == 0) {
        ll ans = 1;
        for (int i = 1; i <= k; ++i)
            ans = (ans * b[i].first) % mod;
        cout << ans << "\n";
        return;
    }


    int n_pos = -1, n_neg = -1;
    for (int i = k + 1; i <= n; ++i) {
        if (b[i].first == 0) continue;
        if (a[b[i].second] > 0 && n_pos == -1) n_pos = i;
        if (a[b[i].second] < 0 && n_neg == -1) n_neg = i;
    }

    int neg = -1, pos = -1;
    for (int i = k; i >= 1; --i) {
        if (a[b[i].second] > 0 && pos == -1) pos = i;
        if (a[b[i].second] < 0 && neg == -1) neg = i;
    }

    if (n_pos == -1) {
        ll ans = 1;
        for (int i = 1; i <= k; ++i)
            ans = (ans * b[i].first) % mod;

        ans = (ans * b[n_neg].first) % mod;
        ans = (ans * binpow(b[pos].first, mod - 2)) % mod;
        cout << ans << "\n";
        return;
    }

    if (n_neg == -1 || pos == -1) {
        ll ans = 1;
        for (int i = 1; i <= k; ++i)
            ans = (ans * b[i].first) % mod;
        ans = (ans * b[n_pos].first) % mod;
        ans = (ans * binpow(b[neg].first, mod - 2)) % mod;
        cout << ans << "\n";
        return;
    }

    if (b[n_pos].first * b[pos].first > b[n_neg].first * b[neg].first) {

        ll ans = 1;
        for (int i = 1; i <= k; ++i)
            ans = (ans * b[i].first) % mod;
        ans = (ans * b[n_pos].first) % mod;
        ans = (ans * binpow(b[neg].first, mod - 2)) % mod;
        cout << ans << "\n";
        return;
    } else {
        ll ans = 1;
        for (int i = 1; i <= k; ++i)
            ans = (ans * b[i].first) % mod;

        ans = (ans * b[n_neg].first) % mod;
        ans = (ans * binpow(b[pos].first, mod - 2)) % mod;
        cout << ans << "\n";
    }
}

int main() {
//    freopen("sample.in", "r", stdin);
    dracarys
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 9004