#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, x); }
template<class T, class U> void init(vector<T> &v, U x, size_t n, size_t m...) { v=vector<T>(n); for(auto& a : v) init(a, x, m);}
const ll MOD = 1e9 + 7;

ll bf(vector<ll>& a, int n, int k){
    double prod = -1e300;
    ll ret = 1;
    FOR(mask, 1 << n){
        int pc = 0;
        FOR(j, n) pc += (mask >> j) & 1;
        if (pc == k){
            bool pos = 1;
            double bigp = 1;
            ll p = 1;
            FOR(i, n){
                if ((mask >> i) & 1){
                    if (a[i] < 0)
                        pos ^= 1;
                    bigp *= a[i];
                    p = p * (MOD + a[i]) % MOD;
                }
            }
//            if (!pos) logp = -logp;
            if (bigp > prod){
                prod = bigp;
                ret = p;
            }
        }
    }
    return ret;
}

//#define TEST 4
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    FOR(tt, 1) {

        int n, k;
#if TEST
        n = 1+rand()%10;
        k = 1+rand()%n;
#else
        cin >> n >> k;
#endif
        vector<ll> a(n);
        int k0 = k;
#if TEST
        srand(tt);
        FOR(i, n) a[i] = -10 + rand() % 20;
#else
        FOR(i, n) cin >> a[i];
#endif
        sort(a.begin(), a.end());

        ll sol = 1;
        if (k % 2 == 0) {
            int i = 0, j = n - 1;
            while (k) {
                if (a[i] * a[i + 1] > a[j] * a[j - 1]) {
                    sol = sol * a[i] % MOD * a[i + 1] % MOD;
                    i += 2;
                } else {
                    sol = sol * a[j] % MOD * a[j - 1] % MOD;
                    j -= 2;
                }
                k -= 2;
                sol = sol + MOD;
                sol %= MOD;
            }
        } else {
            if (a[n - 1] < 0) {
                FOR(i, k)sol = sol * (MOD + a[n - 1 - i]) % MOD;
            } else {
                sol = a[n - 1];
                int i = 0, j = n - 2;
                k--;
                while (k) {
                    if (a[i] * a[i + 1] > a[j] * a[j - 1]) {
                        sol = sol * a[i] % MOD * a[i + 1] % MOD;
                        i += 2;
                    } else {
                        sol = sol * a[j] % MOD * a[j - 1] % MOD;
                        j -= 2;
                    }
                    k -= 2;
                    sol = sol + MOD;
                    sol %= MOD;
                }
            }
        }
        cout << sol << endl;
#if TEST
        ll sol2 = bf(a, n, k0);
        if (sol2 != sol) {
            cout << sol2 << endl;
            return -1;
        }
#endif
    }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



Measured memory_bytes: 4756