#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    ll n,k;
    cin>>n>>k;
    vll a(n);
    cin>>a;
    int numzeros = 0;
    REP(i,n){
        if (a[i] == 0) ++numzeros;
    }
    if (k + numzeros > n){
        cout << 0 << endl;
        return 0;
    }
    vector<pll> p;
    REP(i,n){
        if (a[i] == 0) continue;
        ll now = abs(a[i]);
        p.push_back(make_pair(now, (a[i] < 0 ? -1 : 1)));
    }
    sort(p.begin(),p.end());
    reverse(p.begin(), p.end());
    int sign = 0;
    map<int, vint> ma;
    REP(i, k) {
        if (p[i].second < 0){
            ++sign;
            ma[-1].push_back(i);
        }else{
            ma[1].push_back(i);
        }
    }
    if (sign % 2 == 0){
        ll ans = 1;
        REP(i, k) { ans = (ans * p[i].first) % MOD; }
        cout << ans << endl;
        return 0;
    } else {
        double nowval = -1.;
        pint pidx {-1,-1};
        FOR(i, k, p.size()) {
            //cerr << "test" << endl;
            int twoidx = -1;
            double curval = 1.;
            if (p[i].second < 0) {
                //cout << ma[1].size() << endl;
                if (ma[1].size() > 0) {
                    int val = p[*ma[1].rbegin()].first;
                    twoidx = *ma[1].rbegin();
                    curval = (double)(1. * val) / (double)(1. * p[i].first);
                }
            } else {
                //cout << ma[-1].size() << endl;
                if (ma[-1].size() > 0) {
                    //cout << *ma[-1].rbegin() << endl;
                    int val = p[*ma[-1].rbegin()].first;
                    //cout << "*ma[-1].rbegin()" << endl;
                    twoidx = *ma[-1].rbegin();
                    curval = (double)(1. * val) / (double)(1. * p[i].first);
                }
            }
            //cerr << "test2" << endl;
            if (twoidx != -1){
                if (nowval < 0 || (nowval > curval)){
                    nowval = curval;
                    pidx.first = twoidx;
                    pidx.second = i;
                }
            }
        }
        if (pidx.first == -1){
            if (numzeros > 0){
                cout << 0 << endl;
                return 0;
            }
            int cnt = 0;
            ll ans = 1;
            IREP(i, p.size()) {
                ans = (ans * p[i].first) % MOD;
                ++cnt;
                if (cnt == k) break;
            }

            cout << MOD - ans << endl;
            return 0;
        } else {
            ll ans = 1;
            REP(i,k){
                if (i == pidx.first) continue;
                ans = (ans * p[i].first) % MOD;
            }
            ans = (ans * p[pidx.second].first) % MOD;
            cout<<ans<< endl;
            return 0;
        }
    }
}

Measured memory_bytes: 9660