#include <bits/stdc++.h>

#define fr(i, a, b) for(int i = (a); i <= (b); i++)
#define rf(i, a, b) for(int i = (a); i >= (b); i--)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int mod = 1e9 + 7;
const int inf = 2e9;

int mul(int a, int b) {
    return 1LL * a * b % mod;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
 
    int n, k;
    cin >> n >> k;
    ve<pii> a(n);

    fr(i, 0, n - 1) {
        cin >> a[i].fi;
        a[i].se = (a[i].fi < 0 ? -1 : 1);
        a[i].fi = abs(a[i].fi);
    }
    sort(all(a), [](pii a, pii b) {
        return a.fi > b.fi;
    });

    int neg = 0;
    fr(i, 0, k - 1) {
        neg += (a[i].se == -1);
    }

    // fr(i, 0, n - 1) {
    //     cout << a[i].fi << " " << a[i].se << "\n";
    // }

    if(n == k || neg % 2 == 0) {
        int p = 1;
        fr(i, 0, k - 1) p = mul(p, a[i].fi);
        if(neg % 2) {
            cout << (mod - p) % mod << "\n";
        } else {
            cout << p << "\n";
        }
        return 0;
    }

    fr(i, 0, k - 1) {
        if(a[i].fi == 0) {
            cout << "0\n";
            return 0;
        }
    }

    int mn[2] = {inf, inf}, mx[2] = {-inf, -inf};
    int mn_idx[2] = {-1, -1}, mx_idx[2] = {-1, -1};

    fr(i, 0, k - 1) {
        if(a[i].se == -1) {
            if(umn(mn[0], a[i].fi)) {
                mn_idx[0] = i;
            }
        } else {
            if(umn(mn[1], a[i].fi)) {
                mn_idx[1] = i;
            }
        }
    }

    fr(i, k, n - 1) {
        if(a[i].se == -1) {
            if(umx(mx[0], a[i].fi)) {
                mx_idx[0] = i;
            }
        } else {
            if(umx(mx[1], a[i].fi)) {
                mx_idx[1] = i;
            }
        }
    }

    // mx[0] / mn[1] > mx[1] / mn[0]
    if(mx[0] != -inf && mx[1] != -inf && mn[0] != inf && mn[1] != inf) {
        if(1LL * mx[0] * mn[0] > 1LL * mx[1] * mn[1]) {
            int p = 1;
            fr(i, 0, k - 1) {
                if(i == mn_idx[1]) continue;
                p = mul(p, a[i].fi);
            }
            p = mul(p, mx[0]);
            cout << p << "\n";
        } else {
            int p = 1;
            fr(i, 0, k - 1) {
                if(i == mn_idx[0]) continue;
                p = mul(p, a[i].fi);
            }
            p = mul(p, mx[1]);
            cout << p << "\n";          
        }
    } else {
        if(mx[0] != -inf && mn[1] != inf) {
            int p = 1;
            fr(i, 0, k - 1) {
                if(i == mn_idx[1]) continue;
                p = mul(p, a[i].fi);
            }
            p = mul(p, mx[0]);
            cout << p << "\n";
        } else {
            if(mx[1] != -inf && mn[0] != inf) {
                int p = 1;
                fr(i, 0, k - 1) {
                    if(i == mn_idx[0]) continue;
                    p = mul(p, a[i].fi);
                }
                p = mul(p, mx[1]);
                cout << p << "\n";                 
            } else {
                reverse(all(a));
                int p = 1;
                fr(i, 0, k - 1) {
                    p = mul(p, a[i].fi);
                }
                cout << (mod - p) % mod << "\n";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4792