#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define DIVIDER 1000000007LL

ll calc_product(const vector<ll> &nums) {
  ll retv = 1;
  for (auto x : nums) {
    x = (x % DIVIDER + DIVIDER) % DIVIDER;
    retv = (retv * x + DIVIDER) % DIVIDER;
  }
  return retv;
}

ll solve(const vector<ll> &A, int N, int K) {
  vector<ll> A_positive;
  vector<ll> A_negative;
  int A_zero_count = 0;

  // initialize values
  for (auto &&x : A) {
    if (x > 0) {
      A_positive.push_back(x);
    } else if (x < 0) {
      A_negative.push_back(x);
    } else {
      A_zero_count++;
    }
  }

  // if all multiple number should be 0
  if (A_zero_count > N - K) {
    return 0;
  }

  int N_p = A_positive.size();
  int N_n = A_negative.size();

  vector<ll> abs_desc_A = A;
  sort(ALL(abs_desc_A), [](ll x, ll y) { return abs(x) > abs(y); });

  bool is_pos_ans_exist =
      !((N_p + N_n == K && N_p % 2 == 1) || (N_p == 0 && K % 2 == 1));
  if (is_pos_ans_exist) {
    vector<ll> taken_nums(abs_desc_A.begin(), abs_desc_A.begin() + K);
    ll imax_pos_in_K = -1;
    ll imax_neg_in_K = -1;
    bool is_positive = true;
    for (size_t i = 0; i < K; i++) {
      if (abs_desc_A[i] > 0) {
        imax_pos_in_K = i;
      } else {
        imax_neg_in_K = i;
        is_positive = !is_positive;
      }
    }

    if (is_positive) {
      return calc_product(taken_nums);
    } else {
      if (imax_pos_in_K == -1) {
        taken_nums[K - 1] = *(max_element(ALL(A_positive)));
        return calc_product(taken_nums);
      } else {
        ll swap_pos_ratio = -abs_desc_A[imax_neg_in_K];
        ll swap_neg_ratio = -abs_desc_A[imax_pos_in_K];

        int imin_pos_after_K = -1;
        int imin_neg_after_K = -1;
#define is_pos_found_after_K (imin_pos_after_K != -1)
#define is_neg_found_after_K (imin_neg_after_K != -1)
        int i = K;
        while (!(is_pos_found_after_K && is_neg_found_after_K) && i < N) {
          if (abs_desc_A[i] > 0 && !is_pos_found_after_K) {
            swap_neg_ratio *= abs_desc_A[i];
            imin_pos_after_K = i;
          } else if (abs_desc_A[i] < 0 && !is_neg_found_after_K) {
            swap_pos_ratio *= abs_desc_A[i];
            imin_neg_after_K = i;
          } else if (abs_desc_A[i] == 0) {
            break;
          }
          i++;
        }

        bool is_pos_swap_better =
            ((swap_pos_ratio <= swap_neg_ratio) && is_neg_found_after_K) ||
            !is_pos_found_after_K;
        if (is_pos_swap_better) {
          taken_nums[imax_pos_in_K] = abs_desc_A[imin_neg_after_K];
        } else {
          taken_nums[imax_neg_in_K] = abs_desc_A[imin_pos_after_K];
        }
        return calc_product(taken_nums);
      }
    }
  }

  if (A_zero_count != 0) {
    return 0;
  }

  // if answer is negative number
  vector<ll> abs_asc_A = abs_desc_A;
  reverse(ALL(abs_asc_A));
  vector<ll> taken_nums(abs_asc_A.begin(), abs_asc_A.begin() + K);
  return calc_product(taken_nums);
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  std::vector<ll> A(N, 0);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  // main procedure
  ll ans = solve(A, N, K);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11024