// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>
#define fir first
#define sec second

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

const int N = 500005;
const ll mod = 1e9 + 7;
ll a[N], zs[N], fs[N];
int n, k;

long double f1[N], f2[N];

int main() {
  scanf("%d%d", &n, &k);
  int z = 0, f = 0, zero = 0;
  for (rint i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] > 0) {
      zs[++z] = a[i];
    }
    if (a[i] < 0) {
      fs[++f] = a[i];
    }
    if (a[i] == 0) {
      zero++;
    }
  }
  sort(zs + 1, zs + z + 1, [&](ll x, ll y) {
    return x > y;
  });
  sort(fs + 1, fs + f + 1);
  for (rint i = 1; i <= z; i++) f1[i] = f1[i - 1] + log(zs[i]);
  for (rint i = 1; i <= f; i++) f2[i] = f2[i - 1] + log(-fs[i]);
  
  ll ans = 1;
  
  if (z + f / 2 * 2 >= k && !(!z && k % 2 == 1)) { // 乘积 > 0 
    long double anss = 0;
    int id = 0;
    for (rint i = 0; i <= f && i <= k; i += 2) {
      if (k - i <= z && f2[i] + f1[k - i] >= anss) {
        anss = f2[i] + f1[k - i];
        id = i;
      }
    }
    //cerr << "id = " << id << '\n';
    for (rint i = 1; i <= id; i++) ans = ans * fs[i] % mod;
    for (rint i = 1; i <= k - id; i++) ans = ans * zs[i] % mod;
    printf("%lld\n", (ans % mod + mod) % mod);
  } else if (zero) {
    printf("0\n");
  } else {
    sort(zs + 1, zs + z + 1);
    sort(fs + 1, fs + f + 1, [&](ll x, ll y) {
      return x > y;
    });
    mset(f1, 0), mset(f2, 0);
    for (rint i = 1; i <= z; i++) f1[i] = f1[i - 1] + log(zs[i]);
    for (rint i = 1; i <= f; i++) f2[i] = f2[i - 1] + log(-fs[i]);
    long double anss = -1;
    int id = 0;
    for (rint i = 1; i <= f && i <= k; i += 2) {
      if (k - i <= z && (f2[i] + f1[k - i] <= anss || anss == -1)) {
        anss = f2[i] + f1[k - i];
        id = i;
      }
    }
    //cerr << "id = " << id << '\n';
    for (rint i = 1; i <= id; i++) ans = ans * fs[i] % mod;
    for (rint i = 1; i <= k - id; i++) ans = ans * zs[i] % mod;
    printf("%lld\n", (ans % mod + mod) % mod);
  }
  
  /*
  ll ans = 1;
  if (z >= k) {
    int x = zs.size() - 1;
    while (k--) {
      ans = ans * zs[x--] % mod; 
    }
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    exit(0);
  } else {
    ll k2 = k - z;
    if (f >= k2 && k2 % 2 == 0) {
      for (auto v: zs) ans = ans * v % mod;
      int x = 0;
      while (k2--) ans = ans * fs[x++] % mod;
      ans = (ans % mod + mod) % mod;
      printf("%lld\n", ans);
      exit(0);
    }
    if (f >= k2 + 1 && k2 % 2 == 1) {
      for (rint i = 1; i < zs.size(); i++) ans = ans * zs[i] % mod;
      int x = 0;
      k2++;
      while (k2--) ans = ans * fs[x++] % mod;
      ans = (ans % mod + mod) % mod;
      printf("%lld\n", ans);
      exit(0); 
    }
    printf("%lld\n", 0);
  }
  return 0;
  */
}

Measured memory_bytes: 22504