#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    int cnt = 0, ok = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0) ++cnt;
        if (a[i] == 0) ++ok;
    }
    int pos = n - cnt - ok;
    bool mx = false, can = false;
    for (int p = 0; p <= pos; p++) {
        int neg = k - p;
        if (neg <= cnt) {
            can = true;
            if (neg % 2 == 0) {
                mx = true;
                break;
            }
        }
    }
    if (!can) {
        cout << "0\n";
        rr;
    }
    if (!mx && ok) {
        cout << "0\n";
        rr;
    }
    int ans = 1;
    vector <int> positive, neg;
    for (int i = 0; i < n; i++) {
        if (a[i] > 0) positive.pb(a[i]);
        if (a[i] < 0) neg.pb(a[i]);
    }
    if (mx) {

        sort(all(positive));
        sort(all(neg));
        reverse(all(positive));
        vector <ld> pref_p(sz(positive)), pref_n(sz(neg));
        for (int i = 0; i < sz(positive); i++) {
            pref_p[i] = log((ld)positive[i]);
            if (i) pref_p[i] += pref_p[i - 1];
        }
        for (int i = 0; i < sz(neg); i++) {
            pref_n[i] = log((ld)-neg[i]);
            if (i) pref_n[i] += pref_n[i - 1];
        }
        vector <int> suff(sz(neg));
        for (int i = 0; i < sz(neg); i++) {
            suff[i] = neg[i] + MOD;
            if (i) suff[i] = ((ll)suff[i] * suff[i - 1]) % MOD;
        }
        ld res = -INF;
        int mul = 1;
        for (int i = 0; i <= sz(positive); i++) {
            int N = k - i;

            if (N % 2 == 0 && N <= sz(neg) && N >= 0) {
                ld cur = (i ? pref_p[i - 1] : (ld)0) + (N ? pref_n[N - 1] : (ld)0);
                if (umax(res, cur)) {
                    ans = ((ll)mul * (N ? suff[N - 1] : 1)) % MOD;
                }
            }
            if (i < sz(positive)) mul = ((ll)mul * positive[i]) % MOD;

        }
    }
    else {

        sort(all(positive));
        sort(all(neg));
        reverse(all(neg));
        vector <ld> pref_p(sz(positive)), pref_n(sz(neg));
        for (int i = 0; i < sz(positive); i++) {
            pref_p[i] = log((ld)positive[i]);
            if (i) pref_p[i] += pref_p[i - 1];
        }
        for (int i = 0; i < sz(neg); i++) {
            pref_n[i] = log((ld)-neg[i]);
            if (i) pref_n[i] += pref_n[i - 1];
        }
        vector <int> suff(sz(neg));
        for (int i = 0; i < sz(neg); i++) {
            suff[i] = neg[i] + MOD;
            if (i) suff[i] = ((ll)suff[i] * suff[i - 1]) % MOD;
        }
        ld res = INF;
        int mul = 1;
        for (int i = 0; i <= sz(positive); i++) {
            int N = k - i;
            if (N <= sz(neg) && N >= 0) {
                ld cur = (i ? pref_p[i - 1] : (ld)0) + (N ? pref_n[N - 1] : (ld)0);
                if (umin(res, cur)) {
                    ans = ((ll)mul * (N ? suff[N - 1] : 1)) % MOD;
                }
            }
            if (i < sz(positive)) mul = ((ll)mul * positive[i]) % MOD;

        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 8796