#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <cstring>
#include <cassert>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif

//#define int ll
//#pragma GCC optimize("Ofast")


using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#define sz(x) int((x).size())

#ifdef ONLINE_JUDGE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#else
mt19937 rng(1000 - 7);
#endif

const int N = 2e5 + 10;
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 3;
//const int MOD = 998244353;
const int MOD = 1e9 + 7;
const ld eps = 1e-6;
const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };

ld pref[N], suff[N];
ll sp[N], ss[N];
vector <ll> a;

#define log(x) log(ld(x))

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(9);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

    bool flag = false;
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        if (x) {
            a.push_back(x);
        }
        else {
            flag = true;
        }
    }
    n = sz(a);
    if (k > n) {
        return cout << "0\n", 0;
    }

    sort(a.begin(), a.end());
    if (a[0] > 0) {
        pref[0] = log(a[0]);
        sp[0] = 1;
    }
    else {
        pref[0] = log(-a[0]);
        sp[0] = -1;
    }

    for (int i = 1; i < n; i++) {
        if (a[i] > 0) {
            pref[i] = pref[i - 1] + log(a[i]);
            sp[i] = sp[i - 1];
        }
        else {
            pref[i] = pref[i - 1] + log(-a[i]);
            sp[i] = -sp[i - 1];
        }
    }

    suff[n] = 0, ss[n] = 1;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > 0) {
            suff[i] = suff[i + 1] + log(a[i]);
            ss[i] = ss[i + 1];
        }
        else {
            suff[i] = suff[i + 1] + log(-a[i]);
            ss[i] = -ss[i + 1];
        }  
    }

    int j = -1;
    ld m = suff[n - k] * ss[n - k];

    for (int i = 0; i < k; i++) {
        ld cur = (pref[i] + suff[n - k + i + 1]) * sp[i] * ss[n - k + i + 1];
        if (cur > m) {
            m = cur;
            j = i;
        }
    }

    debug(a);
    debug(suff[0], ss[0]);
    debug(m, j);
    if (m <= 0 && flag) {
        return cout << "0\n", 0;
    }

    ll ans = 1;
    for (int i = 0; i <= j; i++) {
        ans = (ans * a[i]) % MOD;
    }

    for (int i = n - 1; i >= n - k + j + 1; i--) {
        ans = (ans * a[i]) % MOD;
    }

    ans = (MOD + ans) % MOD;
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 14408