#include <bits/stdc++.h>
using namespace std;
 
int64_t mod(int64_t a, int64_t b) {
  if (a >= 0) {
    return a % b;
  } else {
    int64_t bb = ((-a) % b);
    if (bb == 0) {
      return 0;
    } else {
      return b - bb;
    }
  }
}
int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<int64_t> A(N);
 
  int64_t DIV = 1000000007LL;
 
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
 
  vector<int64_t> PLUSS;
  vector<int64_t> MINUSS;
  vector<int64_t> ZEROS;
  for (auto a : A) {
    if (a > 0) {
      PLUSS.push_back(a);
    } else if (a < 0) {
      MINUSS.push_back(a);
    } else {
      ZEROS.push_back(a);
    }
  }
 
  // ゼロ以下
  if (PLUSS.size() + MINUSS.size() < K) {
    cout << "0" << endl;
    return 0;
  } else if (PLUSS.size() == 0 && K % 2 == 1) {
    if (ZEROS.size() > 0) {
      cout << "0" << endl;
      return 0;
    } else {
      sort(MINUSS.begin(), MINUSS.end(),
           [](int64_t a, int64_t b) { return a > b; });
      int64_t cumul = 1;
      int j = 0;
      while (j < K) {
        if (j + 2 <= K) {
          cumul = mod(cumul * mod(MINUSS[j] * MINUSS[j + 1], DIV), DIV);
          j += 2;
        } else {
          cumul = mod(cumul * MINUSS[j], DIV);
          j++;
        }
      }
      cout << cumul << endl;
      return 0;
    }
  } else if (MINUSS.size() + PLUSS.size() == K && MINUSS.size() % 2 == 1) {
    if (ZEROS.size() > 0) {
      cout << "0" << endl;
      return 0;
    } else {
      int64_t cumul = 1;
      for (auto p : PLUSS) {
        cumul = mod(cumul * p, DIV);
      }
      int j = 0;
      while (j < MINUSS.size()) {
        if (j + 2 <= MINUSS.size()) {
          cumul = mod(cumul * mod(MINUSS[j] * MINUSS[j + 1], DIV), DIV);
          j += 2;
        } else {
          cumul = mod(cumul * MINUSS[j], DIV);
          j++;
        }
      }
      cout << cumul << endl;
      return 0;
    }
  }
 
  sort(PLUSS.begin(), PLUSS.end(), [](int64_t a, int64_t b) { return a > b; });
  sort(MINUSS.begin(), MINUSS.end());
 
  int64_t cumul = 1;
  int plus_idx = 0;
  int minus_idx = 0;
  int cnt = 0;
  while (true) {
    if (cnt == K) {
      break;
    } else if (cnt + 1 == K) {
      cumul = mod(cumul * PLUSS[plus_idx], DIV);
      plus_idx++;
      cnt++;
    } else if (minus_idx + 1 >= MINUSS.size()) {
      cumul = mod(cumul * PLUSS[plus_idx], DIV);
      plus_idx++;
      cnt++;
    } else if (plus_idx + 1 >= PLUSS.size()) {
      cumul =
          mod(cumul * mod(MINUSS[minus_idx] * MINUSS[minus_idx + 1], DIV), DIV);
      minus_idx += 2;
      cnt += 2;
    } else if (cnt + 3 == K) {
      // + ++
      // + --
      bool ppp = false;
      if (plus_idx + 3 <= PLUSS.size()) {
        int64_t pp = PLUSS[plus_idx + 1] * PLUSS[plus_idx + 2];
        int64_t mm = MINUSS[minus_idx] * MINUSS[minus_idx + 1];
        if (pp >= mm) {
          ppp = true;
        }
      } 
      if (ppp) {
        cumul = mod(cumul * mod(PLUSS[plus_idx] * mod(PLUSS[plus_idx + 1] * PLUSS[plus_idx + 2], DIV), DIV), DIV);
        plus_idx += 3;
        cnt += 3;
      } else {
        cumul = mod(cumul * mod(PLUSS[plus_idx] * mod(MINUSS[minus_idx] * MINUSS[minus_idx + 1], DIV), DIV), DIV);
        plus_idx += 1;
        minus_idx += 2;
        cnt += 3;
      }
    } else if ((plus_idx + 2 == PLUSS.size()) && ((K - cnt) % 2) == 1) {
      cumul = mod(cumul * PLUSS[plus_idx], DIV);
      plus_idx++;
      cnt++;
    } else if ((plus_idx + 2 <= PLUSS.size()) &&
               (minus_idx + 2 <= MINUSS.size())) {
      int64_t plus_pair = PLUSS[plus_idx] * PLUSS[plus_idx + 1];
      int64_t minus_pair = MINUSS[minus_idx] * MINUSS[minus_idx + 1];
      if (plus_pair >= minus_pair) {
        cumul = mod(cumul * mod(plus_pair, DIV), DIV);
        plus_idx += 2;
      } else {
        cumul = mod(cumul * mod(minus_pair, DIV), DIV);
        minus_idx += 2;
      }
      cnt += 2;
    } else {
      cnt++;
    }
  }
 
  cout << cumul << endl;
  return 0;
}


Measured memory_bytes: 6976