#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#include <unordered_set>
#include <unordered_map>
#include <numeric>

using ll = long long;

using LL = long long;
using namespace std;

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
template<class T> void _R(std::vector<T>& v) { for (auto& e : v) { _R(e); } }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;

void AllElements(const vector<ll>& a) {
  cout << std::accumulate(a.begin(), a.end(), 1, [](const auto& lhs, const auto& rhs) { 
      return (((lhs % MOD) * (rhs % MOD)) % MOD + MOD) % MOD;
  }) << endl;
  /*ll res = 1;
  for (const auto& e : a) {
    res *= e;
    res %= MOD;
    res = (res + MOD) % MOD;
  }
  W(res);*/
}

void NegativeResult(vector<ll>& a, ll k) {
    std::sort(a.begin(), a.end(), std::greater<ll>());
    std::cout << std::accumulate(a.begin(), a.begin() + k, 1, [](const auto& lhs, const auto& rhs) {
        return ((lhs * rhs + MOD) % MOD);
    }) << std::endl;
}

ll PositiveCount(const vector<ll>& a) {
  ll pos_c = 0;
  std::for_each(a.begin(), a.end(), [&pos_c](ll elem) { if (elem >= 0) { ++pos_c; }});
  return pos_c;
}

void GeneralCase(vector<ll>& a, ll pos_c, ll k) {
  // Create arrays with pos and neg elements
  std::sort(a.begin(), a.end());
  // W("a = ", a);
  std::vector<ll> pos, neg;
  for (auto e : a) {
    if (e >= 0) {
      pos.push_back(e);
    } else {
      neg.push_back(e);
    }
  }

  // Special case for k % 2 == 1: remove maximum
  ll ans = 1;
  if (k % 2 == 1) {
    ans *= pos.back();
    pos.pop_back();
    --k;
  }

  std::reverse(pos.begin(), pos.end());

  // W("pos = ", pos);
  // W("neg = ", neg);

  std::vector<ll> p;
  for (size_t i = 0; i + 1 < pos.size(); i += 2) {
    p.push_back(pos[i] * pos[i + 1]);
  }
  for (size_t i = 0; i + 1 < neg.size(); i += 2) {
    p.push_back(neg[i] * neg[i + 1]);
  }
  std::sort(p.begin(), p.end(), std::greater<ll>());
  // W("p = ", p);

  for (auto it = p.begin(); k > 0; k -= 2, ++it) {
    ans *= (*it + MOD) % MOD;
    ans = (ans + MOD) % MOD;
  }

  W(ans);
}

int main() {
  ll n, k;
  std::cin >> n >> k;
  std::vector<ll> a(n);
  for (auto& e : a) {
    std::cin >> e;
  }

  if (n == k) {
    AllElements(a);
  } else {
    auto pos_c = PositiveCount(a);
    if (pos_c == 0 && k % 2 == 1) {
      NegativeResult(a, k);
    } else {
      GeneralCase(a, pos_c, k);
    }
  }

  return 0;
}


Measured memory_bytes: 8104