#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
struct mint {
  int x; // typedef long long ll;
  mint(int 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(int 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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
    vector<int> par, size;
    UnionFind(int x) {
        par.resize(x);
        size.resize(x, 1);
        for(int i = 0; i < x; i++) {
            par[i] = i;
        }
    }
    int find(int x) {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int consize(int x) {
        return size[find(x)];
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size[x] < size[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
        }
    }
};
signed main() {
    int N,K;
    cin >> N >>K;
    vector<int>A(N);
    vector<int>X;
    vector<int>Y;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] < 0) {
            Y.push_back(A[i]);
        }
        else {
            X.push_back(A[i]);
        }
    }
    int x = X.size();
    int y = Y.size();
    bool ok = false;
    if(x > 0) {
        if(N == K) ok = (y%2 == 0);
        else ok = true;
    }
    else {
        ok = (K%2 == 0);
    }
    mint ans = 1;
    if(!ok) {
        sort(A.begin(),A.end(),[](int x,int y) {return abs(x) < abs(y);});
        for(int i = 0; i < K; i++) {
            ans*=A[i];

        }
    }
    else {
        sort(X.begin(),X.end());
        sort(Y.begin(),Y.end());
        reverse(Y.begin(),Y.end());
        if(K%2 == 1) {
            ans*=X.back();
            X.pop_back();
        }
        vector<int> p;
        while(X.size() >= 2) {
            int T = X.back(); X.pop_back();
            T *= X.back();X.pop_back();
            p.push_back(T);
        }
        while(Y.size() >= 2) {
            int T = Y.back(); Y.pop_back();
            T *= Y.back();Y.pop_back();
            p.push_back(T);
        }
        sort(p.begin(),p.end());
        reverse(p.begin(),p.end());
        for(int i = 0; i < K/2; i++) {
            ans*=p[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8200