#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = int(2e9);
const long long LINF = long long(2e9) * long long(2e9);
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  int K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<long long> plusA, minusA, zeroA;
  long long p = 1000000007;
  for (int i = 0; i < N; i++) {
    if (A[i] >= 0)
      plusA.push_back(A[i]);
    else if (A[i] < 0)
      minusA.push_back(A[i]);
    else
      zeroA.push_back(abs(A[i]));
  }
  if (K == N) {
    long long ans = 1;
    for (int i = 0; i < N; i++) {
      ans *= A[i];
      ans = mod(ans, p);
    }
    cout << ans << endl;
    return 0;
  }
  if (plusA.size() == 0) {
    if (K % 2 == 0) {
      sort(minusA.begin(), minusA.end());
    } else {
      sort(minusA.begin(), minusA.end(), greater<long long>());
    }
    long long ans = 1;
    for (int i = 0; i < K; i++) {
      ans *= minusA[i];
      ans = mod(ans, p);
    }
    cout << ans << endl;
    return 0;
  }
  sort(plusA.begin(), plusA.end(), greater<long long>());
  sort(minusA.begin(), minusA.end(), greater<long long>());
  vector<pair<long long, long long>> plusAS(plusA.size() + 1),
      minusAS(minusA.size() + 1);
  plusAS[0] = make_pair(1, 0);
  minusAS[0] = make_pair(1, 0);
  for (int i = 0; i < plusA.size(); i++) {
    plusAS[i + 1].first = plusAS[i].first * plusA[i];
    plusAS[i + 1].first = mod(plusAS[i + 1].first, p);
    if (plusAS[i + 1].first != plusAS[i].first * plusA[i]) {
      plusAS[i + 1].second++;
    }
  }
  for (int i = 0; i < minusA.size(); i++) {
    minusAS[i + 1].first = minusAS[i].first * minusA[i];
    minusAS[i + 1].first = mod(minusAS[i + 1].first, p);
    if (minusAS[i + 1].first != minusAS[i].first * minusA[i]) {
      minusAS[i + 1].second++;
    }
  }
  int PN = plusA.size();
  int MN = minusA.size();
  pair<long long, long long> ans = make_pair(0, 0);
  for (int i = 0; i <= MN; i += 2) {
    int j = K - i;
    if (j < 0) continue;
    if (j > PN) continue;
    long long X = plusAS[j].first * minusAS[i].first;
    X = mod(X, p);
    long long C = plusAS[j].second + minusAS[i].second;
    if (X != plusAS[j].first * minusAS[i].first) C++;
    if (C > ans.second) {
      ans.first = X;
      ans.second = C;
    } else if (C == ans.second) {
      if (X > ans.first) {
        ans.first = X;
        ans.second = C;
      }
    }
  }
  cout << ans.first << endl;
  return 0;
}
