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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  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;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { 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;}

mint solve(pair<ll,int> a[], int n, int k) {
    
    // 全部負の数で kが奇数個ならば 結果は負になるので昇順で並べたものが答え
    int minus = 0;
    rep0(i,n) if (a[i].second < 0) minus++;
    debug(minus);
    if ((minus == n && k % 2 == 1) || n == k) {
        sort(a,a+n);
        mint ans = 1;
        rep0(i,k) {
            ans *= a[i].first * a[i].second;
        }
        return ans;
    }

    // それ以外は必ず正の値にできるので絶対値の多い順に取っていく
    sort(a,a+n,greater<pair<ll,int>>());

    mint ans = mint(1);
    int i=0;
    int sign = 1;
    ll last_minus = 0;
    ll last_plus = 0;
    for (;i < k; i++) {
        ans *= a[i].first;
        sign *= a[i].second;
        if (a[i].second < 0) {
            last_minus = a[i].first;
        } else {
            last_plus = a[i].first;
        }
    }
    // 結果が正ならそれが解答
    if (sign > 0) {
        return ans;
    }

    //  k    data
    //  odd  all negative  -- cond1
    //  odd  all positive  -- cond2
    //  even  all negative  -- cond2
    //  even  all positive  -- cond2
    //  odd   k:nega remain:posi - 
    //  odd   k:posi remain:nega - cond2
    //  even  k:nega remain:posi - cond2
    //  even  k:nega remain:nega 
    //  even  k:posi remain:nega - cond2
    //  even  k:posi remain:nega
    // 
    // 最小の正の数を除いて k+1から最大の負の数を加える or 最小の負の数を除いて  k+1から最大の正の数を加える のどちらか
    ll remain_plus = 0;
    ll remain_minus = 0;
    for (int j=i;j<n;j++) if (a[j].second > 0) { remain_plus = a[j].first; break;}
    for (int j=i;j<n;j++) if (a[j].second < 0) { remain_minus = a[j].first; break;}
    debug(sign, last_plus, last_minus, remain_plus, remain_minus);
    if (remain_plus == 0 || last_minus == 0) {
        return ans * remain_minus / last_plus;
    }
    if (remain_minus == 0 || last_plus == 0) {
        return ans * remain_plus / last_minus;
    }
    if (remain_plus * last_plus > remain_minus * last_minus) {
        return ans * remain_plus / last_minus;
    }
    return ans * remain_minus / last_plus;
}

int main() {
    FAST_IOSTREAM();

    int n, k;
    cin >> n >> k;
    pair<ll,int> a[n];
    rep0(i,n) {
        int x;
        cin >> x;
        a[i] = {abs(x), (x<0) ? -1: 1};
    }

    mint ans = solve(a, n, k);

    cout << ans << endl;
}


Measured memory_bytes: 6788