#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+10;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

bool comp(int a, int b) {
    return abs(a) > abs(b);
}

int main() {
    int n, k; cin >> n >> k;
    vint a(n);
    int ct_minus = 0;
    rep(i,n) {
        int x; cin >> x;
        a[i] = x;
        if (x < 0) ct_minus++;
    }
    mint ans = 1;
    if ((n == k && ct_minus & 1) || (n != k && ct_minus == n && k & 1)) {
        sort(rall(a));
        rep(i,k) ans *= a[i];
    } else {
        sort(all(a),[](int a, int b) {return abs(a) > abs(b);});
        ct_minus = 0;
        rep(i,k) ans *= a[i];
        rep(i,k) if (a[i] < 0) ct_minus++;
        if (ct_minus % 2 != 0) {
            int x1 = inf, y1 = inf, x2 = inf, y2 = inf;
            for (int j = k-1; j >= 0; j--) {
                if (a[j] < 0 && x1 == inf) x1 = -a[j];
                if (a[j] >= 0 && x2 == inf) x2 = a[j]; 
            }
            for (int j = k; j < n; j++) {
                if (a[j] >= 0 && y1 == inf) y1 = a[j];
                if (a[j] < 0 && y2 == inf) y2 = -a[j];
            }
            if ((x2 == inf || y2 == inf) || (x1 == inf || y1 == inf)) {
                if (x2 == inf || y2 == inf) {
                    ans = ans / (-x1) * y1;
                } else {
                    ans = ans / x2 * (-y2);
                }
            } else {
                if ((ll)y1*x2 < (ll)y2*x1) {
                    ans = ans / x2 * (-y2);
                } else {
                    ans = ans / (-x1) * y1;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4024