#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;
const ll mod = 1000000007;

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) const { return mint(*this)/=a; }
  bool operator==(const mint a) const { return x == a.x; }
  bool operator!=(const mint a) const { return x != a.x; }
  friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};

int main()
{
  ll n; cin >> n;
  ll k; cin >> k;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }

  sort(a.begin(),a.end());

  vector<ll> pos;
  vector<ll> neg;
  rep(i, n) {
    if (a[i] > 0) pos.push_back(a[i]);
    if (a[i] < 0) neg.push_back(-a[i]);
  }
  ll pn = pos.size();
  ll nn = neg.size();
  ll z = n - pn - nn;

  if (pn+nn < k) {
    cout << 0 << endl;
    return 0;
  }

  sort(pos.rbegin(),pos.rend());
  sort(neg.rbegin(),neg.rend());

  if (pn == 0) {
    if (k%2) {
      sort(neg.begin(),neg.end());
      mint tmp = 1;
      for (int i=0; i<k; i++) {
        tmp *= neg[i];
      }
      if (z > 0) cout << 0 << endl;
      else cout << mod - tmp.x << endl;
    } else {
      mint tmp = 1;
      for (int i=0; i<k; i++) {
        tmp *= neg[i];
      }
      cout << tmp << endl;
    }
    return 0;
  }
  if (nn == 0) {
    mint tmp = 1;
    for (int i=0; i<k; i++) tmp *= pos[i];
    cout << tmp << endl;
    return 0;
  }
  if (pn+nn == k) {
    mint tmp = 1;
    for (auto v:pos) tmp *= v;
    for (auto v:neg) tmp *= v;
    if (nn%2) {
      if (z > 0) cout << 0 << endl;
      else cout << mod - tmp.x << endl;
    }
    else cout << tmp << endl;
    return 0;
  }

  priority_queue<int, vector<int>, less<int>> poq;
  priority_queue<int, vector<int>, less<int>> neq;
  for (auto v:pos) poq.push(v);
  for (auto v:neg) neq.push(v);

  mint ans = 1;
  while (k) {
    ll x = poq.size();
    ll y = neq.size();
    if (x >= 2 && y >= 2) {
      if (k >= 2) {
        ll p1 = poq.top(); poq.pop();
        ll p2 = poq.top(); poq.pop();
        ll n1 = neq.top(); neq.pop();
        ll n2 = neq.top(); neq.pop();
        if (p1*p2 >= n1*n2) {
          ans *= mint(p1);
          poq.push(p2);
          neq.push(n1); neq.push(n2);
          k--;
        } else {
          ans *= mint(n1) * mint(n2);
          poq.push(p1); poq.push(p2);
          k -= 2;
        }
      } else {
        ll p1 = poq.top(); poq.pop();
        ans *= p1;
        k--;
      }
    } else if (y >= 2) {
      if (k >= 2) {
        ll n1 = neq.top(); neq.pop();
        ll n2 = neq.top(); neq.pop();
        ans *= mint(n1) * mint(n2);
        k -= 2;
      } else {
        if (x > 0) {
          ll p1 = poq.top(); poq.pop();
          ans *= p1;
          cout << ans << endl;
          return 0;
        }
        if (z > 0) {
          cout << 0 << endl;
          return 0;
        }
        ll n1 = neq.top(); neq.pop();
        ans *= n1;
        cout << mod - ans.x << endl;
        k--;
        return 0;
      }
    } else if (x >= 2) {
      if (k >= 2) {
        ll p1 = poq.top(); poq.pop();
        ll p2 = poq.top(); poq.pop();
        ans *= mint(p1) * mint(p2);
        k -= 2;
      } else {
        ll p1 = poq.top(); poq.pop();
        ans *= mint(p1);
        cout << ans << endl;
        k--;
        return 0;
      }
    } else {
      if (x == 1 && y == 1) {
        if (k == 2) {
          if (z > 0) {
            cout << 0 << endl;
            return 0;
          }
          ll p1 = poq.top(); poq.pop();
          ll n1 = neq.top(); neq.pop();
          ans *= mint(p1) * mint(n1);
          cout << mod - ans.x << endl;
          return 0;
        } else {
          ll p1 = poq.top(); poq.pop();
          ans *= mint(p1);
          cout << ans << endl;
          return 0;
        }
      } else if (y == 1) {
        if (z > 0) {
          cout << 0 << endl;
          return 0;
        }
        ll n1 = neq.top(); neq.pop();
        ans *= n1;
        cout << mod - ans.x << endl;
        k--;
        return 0;
      } else if (x == 1) {
        ll p1 = poq.top(); poq.pop();
        ans *= mint(p1);
        cout << ans << endl;
        k--;
        return 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8016