#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll mod(ll v) {
    ll res = v % MOD;
    if(res < 0)
        res += MOD;
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    if(N == K) {
        ll res = 1;
        rep(i, N) { res = mod(res * A[i]); }
        cout << res << endl;
    } else {
        bool is_all_neg = 1;
        rep(i, N) if(A[i] >= 0) is_all_neg = 0;
        if(K % 2 == 1 && is_all_neg) {
            sort(All(A));
            reverse(All(A));
            ll res = 1;
            rep(i, K) {
                res = mod(res * A[i]);
                cerr << res << endl;
            }
            cout << res << endl;
        } else {
            vector<ll> pos, neg;
            rep(i, N) {
                if(A[i] >= 0)
                    pos.pb(A[i]);
                else
                    neg.pb(A[i]);
            }
            sort(All(pos));
            reverse(All(pos));
            sort(All(neg));
            int poscur = 0, negcur = 0;
            ll res = 1, cnt = 0;
            bool is_neg = 0;
            while(cnt != K) {
                ll num = 0;
                if(poscur == pos.size()) {
                    num = neg[negcur++];
                    is_neg = 1 - is_neg;
                } else if(negcur == neg.size()) {
                    num = pos[poscur++];
                } else if(pos[poscur] >= -neg[negcur]) {
                    num = pos[poscur++];
                } else {
                    num = neg[negcur++];
                    is_neg = 1 - is_neg;
                }
                res = mod(res * num);
                cnt++;
            }
            if(!is_neg) {
                cout << res << endl;
            } else {
                ll p1 = LINF, p2 = LINF, n1 = LINF, n2 = LINF;
                if(poscur != pos.size() && negcur != 0) {
                    p1 = pos[poscur];
                    n1 = neg[negcur - 1];
                }
                if(negcur != neg.size() && poscur != 0) {
                    p2 = pos[poscur - 1];
                    n2 = neg[negcur];
                }
                ll res = 1;

                if(p1 == LINF) {
                    for(int i = 0; i < poscur - 1; i++)
                        res = mod(res * pos[i]);
                    for(int i = 0; i <= negcur; i++)
                        res = mod(res * neg[i]);
                    cout << res << endl;
                } else if(p2 == LINF) {
                    for(int i = 0; i <= poscur; i++)
                        res = mod(res * pos[i]);
                    for(int i = 0; i < negcur - 1; i++)
                        res = mod(res * neg[i]);
                    cout << res << endl;
                } else {

                    if(abs(p1 * p2) > abs(n2 * n1)) {
                        for(int i = 0; i <= poscur; i++)
                            res = mod(res * pos[i]);
                        for(int i = 0; i < negcur - 1; i++)
                            res = mod(res * neg[i]);
                        cout << res << endl;
                    } else {
                        for(int i = 0; i < poscur - 1; i++)
                            res = mod(res * pos[i]);
                        for(int i = 0; i <= negcur; i++)
                            res = mod(res * neg[i]);
                        cout << res << endl;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 6928