#line 1 "E.cpp"
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <map>
#include <string>

#line 1 "~/git/library/utility/io.cpp"



/**
 * @brief 入出力
 * @author えびちゃん
 */

#include <cstddef>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <utility>

class format {
public:
  using size_type = size_t;

private:
  char const* M_fmt;
  size_type M_nvars = 0;
  size_type M_error = -1;

  void M_print(std::ostream& os, char const* pos) const {
    while (*pos) {
      if (*pos == '{' || *pos == '}') ++pos;
      os << *pos++;
    }
  }

  template <typename Tp, typename... Args>
  void M_print(std::ostream& os, char const* pos, Tp const& x, Args const&... xs) const {
    while (true) {
      if (*pos == '{') {
        if (pos[1] == '{') {
          ++pos;
          os << '{';
        } else {
          char const* next = M_print_formatted(os, pos, x);
          return M_print(os, next, xs...);
        }
      } else {
        if (*pos == '}') ++pos;
        os << *pos;
      }
      ++pos;
    }
    char const* next = M_print_formatted(os, pos, x);
    M_print(os, next, xs...);
  }

  template <typename Tp>
  char const* M_print_formatted(std::ostream& os, char const* pos, Tp const& x) const {
    // parse flags, preferably
    while (*++pos != '}') {}
    os << x;
    return ++pos;
  }

  void M_scan(std::istream& is, char const* pos) const {
    while (true) {
      if (*pos == '{' || *pos == '}') ++pos;
      if (isspace(*pos)) {
        while (isspace(is.peek())) is.get();
      } else {
        if (is.peek() == *pos) {
          ++pos;
          is.get();
        } else {
          return;
        }
      }
    }
  }

  template <typename Tp, typename... Args>
  void M_scan(std::istream& is, char const* pos, Tp& x, Args&&... xs) const {
    while (true) {
      if (*pos == '{') {
        if (pos[1] == '{') {
          if (is.peek() == '{') {
            ++pos;
            is.get();
          } else {
            return;
          }
        } else {
          char const* next = M_scan_formatted(is, pos, x);
          return M_scan(is, next, xs...);
        }
      } else if (isspace(*pos)) {
        while (isspace(is.peek())) is.get();
        ++pos;
      } else {
        if (*pos == '}') ++pos;
        if (is.peek() == *pos) {
          ++pos;
          is.get();
        } else {
          return;
        }
      }
    }
  }

  template <typename Tp>
  char const* M_scan_formatted(std::istream& is, char const* pos, Tp& x) const {
    // parse flags, preferably
    while (*++pos != '}') {}
    is >> x;
    return ++pos;
  }

public:
  constexpr format(char const* fmt): M_fmt(fmt) {
    bool opens = 0;
    size_type i = 0;
    for (; fmt[i]; ++i) {
      if (fmt[i] == '{') {
        if (fmt[i+1] == '{') { ++i; continue; }  // escaped
        if (opens) { M_error = i; return; }
        opens = true;
      } else if (fmt[i] == '}') {
        if (fmt[i+1] == '}') { ++i; continue; }  // escaped
        if (!opens) { M_error = i; return; }
        opens = false;
        ++M_nvars;
      }
    }
    if (opens) { M_error = i; return; }
  }

  template <typename... Args>
  void print_(std::ostream& os, Args const&... xs) const {
    M_print(os, M_fmt, xs...);
  }

  template <typename... Args>
  void scan_(std::istream& is, Args&&... xs) const {
    M_scan(is, M_fmt, xs...);
  }

  constexpr size_type count() const { return M_nvars; }
  constexpr size_type error() const { return M_error; }
};

#define VA_COUNT(...)                                           \
  std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value

#define fprint(os, fmt, ...) (void)({                           \
      constexpr format fmt_(fmt);                               \
      constexpr size_t lhs = fmt_.count();                      \
      constexpr size_t rhs = VA_COUNT(__VA_ARGS__);             \
      static_assert(lhs == rhs, "size mismatch");               \
      static_assert(fmt_.error()+1 == 0, "misformatted");       \
      fmt_.print_(os, ##__VA_ARGS__);                           \
    })

#define fprintln(os, fmt, ...) (void)({         \
      fprint(os, fmt, ##__VA_ARGS__);           \
      os << '\n';;                              \
    })

#define print(...) fprint(std::cout, ##__VA_ARGS__)
#define println(...) fprintln(std::cout, ##__VA_ARGS__)
#define eprint(...) fprint(std::cerr, ##__VA_ARGS__)
#define eprintln(...) fprintln(std::cerr, ##__VA_ARGS__)

#define fscan(is, fmt, ...) (void)({                            \
      constexpr format fmt_(fmt);                               \
      constexpr size_t lhs = fmt_.count();                      \
      constexpr size_t rhs = VA_COUNT(__VA_ARGS__);             \
      static_assert(lhs == rhs, "size mismatch");               \
      static_assert(fmt_.error()+1 == 0, "misformatted");       \
      fmt_.scan_(is, ##__VA_ARGS__);                            \
    })

#define scan(...) fscan(std::cin, __VA_ARGS__)

__attribute__((constructor))
void ioinit() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cerr.tie(nullptr);
  std::cout << std::fixed << std::setprecision(16);
}


#line 1 "~/git/library/utility/literals.cpp"



/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#line 10 "~/git/library/utility/literals.cpp"
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

constexpr int32_t  operator ""_i32(unsigned long long n) { return n; }
constexpr int64_t  operator ""_i64(unsigned long long n) { return n; }
constexpr uint32_t operator ""_u32(unsigned long long n) { return n; }
constexpr uint64_t operator ""_u64(unsigned long long n) { return n; }


#line 1 "~/git/library/ModularArithmetic/modint.cpp"



/**
 * @brief 合同算術用クラス
 * @author えびちゃん
 */

#line 10 "~/git/library/ModularArithmetic/modint.cpp"
#include <limits>
#include <type_traits>
#line 13 "~/git/library/ModularArithmetic/modint.cpp"

template <intmax_t Modulo>
class modint {
public:
  using value_type = typename std::conditional<
  (0 < Modulo && Modulo < std::numeric_limits<int>::max() / 2), int, intmax_t
 >::type;

private:
  static constexpr value_type S_cmod = Modulo;  // compile-time
  static value_type S_rmod;  // runtime
  value_type M_value = 0;

  static constexpr value_type S_inv(value_type n, value_type m) {
    value_type x = 0;
    value_type y = 1;
    value_type a = n;
    value_type b = m;
    for (value_type u = y, v = x; a;) {
      value_type q = b / a;
      std::swap(x -= q*u, u);
      std::swap(y -= q*v, v);
      std::swap(b -= q*a, a);
    }
    if ((x %= m) < 0) x += m;
    return x;
  }

  static value_type S_normalize(intmax_t n, value_type m) {
    if (n >= m) {
      n %= m;
    } else if (n < 0) {
      if ((n %= m) < 0) n += m;
    }
    return n;
  }

public:
  modint() = default;
  modint(intmax_t n): M_value(S_normalize(n, get_modulo())) {}

  modint& operator =(intmax_t n) {
    M_value = S_normalize(n, get_modulo());
    return *this;
  }

  modint& operator +=(modint const& that) {
    if ((M_value += that.M_value) >= get_modulo()) M_value -= get_modulo();
    return *this;
  }
  modint& operator -=(modint const& that) {
    if ((M_value -= that.M_value) < 0) M_value += get_modulo();
    return *this;
  }
  modint& operator *=(modint const& that) {
    intmax_t tmp = M_value;
    tmp *= that.M_value;
    M_value = tmp % get_modulo();
    return *this;
  }
  modint& operator /=(modint const& that) {
    intmax_t tmp = M_value;
    tmp *= S_inv(that.M_value, get_modulo());
    M_value = tmp % get_modulo();
    return *this;
  }

  modint& operator ++() {
    if (++M_value == get_modulo()) M_value = 0;
    return *this;
  }
  modint& operator --() {
    if (M_value-- == 0) M_value = get_modulo()-1;
    return *this;
  }

  modint operator ++(int) { modint tmp(*this); ++*this; return tmp; }
  modint operator --(int) { modint tmp(*this); --*this; return tmp; }

  friend modint operator +(modint lhs, modint const& rhs) { return lhs += rhs; }
  friend modint operator -(modint lhs, modint const& rhs) { return lhs -= rhs; }
  friend modint operator *(modint lhs, modint const& rhs) { return lhs *= rhs; }
  friend modint operator /(modint lhs, modint const& rhs) { return lhs /= rhs; }

  modint operator +() const { return *this; }
  modint operator -() const {
    if (M_value == 0) return *this;
    return modint(get_modulo() - M_value);
  }

  friend bool operator ==(modint const& lhs, modint const& rhs) {
    return lhs.M_value == rhs.M_value;
  }
  friend bool operator !=(modint const& lhs, modint const& rhs) {
    return !(lhs == rhs);
  }

  value_type get() const { return M_value; }
  static value_type get_modulo() { return ((S_cmod > 0)? S_cmod: S_rmod); }

  template <int M = Modulo, typename Tp = typename std::enable_if<(M <= 0)>::type>
  static Tp set_modulo(value_type m) { S_rmod = m; }
};

template <intmax_t N>
constexpr typename modint<N>::value_type modint<N>::S_cmod;
template <intmax_t N>
typename modint<N>::value_type modint<N>::S_rmod;


#line 11 "E.cpp"

constexpr intmax_t mod = 1000'000'007;
using mi = modint<mod>;

int main() {
  size_t n, k;
  scan("{} {}", n, k);

  std::vector<int64_t> a(n);
  for (auto& ai: a) scan("{}", ai);

  if (k == n) {
    mi res = 1;
    for (auto ai: a) res *= ai;
    return println("{}", res.get()), 0;
  }

  std::vector<int64_t> nz;
  for (auto ai: a) {
    if (ai != 0) nz.push_back(ai);
  }

  if (nz.size() < k)
    return println("0"), 0;

  std::sort(nz.rbegin(), nz.rend());
  if (nz[0] < 0) {
    if (nz.size() < n && nz.size() % 2 == 1) {
      return println("0"), 0;
    }
    if (k % 2 == 0) std::sort(nz.begin(), nz.end());
    mi res = 1;
    for (size_t i = 0; i < k; ++i) res *= nz[i];
    return println("{}", res.get()), 0;
  }

  std::sort(nz.begin(), nz.end(), [](auto x, auto y) {
    return std::abs(x) > std::abs(y);
  });

  size_t i = 0;
  std::vector<int64_t> pos, neg;
  for (; i < nz.size() && pos.size() + neg.size() < k; ++i) {
    ((nz[i] > 0)? pos: neg).push_back(nz[i]);
  }

  eprintln("pos: #{}", pos.size());
  eprintln("neg: #{}", neg.size());

  if (neg.size() % 2 == 0) {
    mi res = 1;
    for (auto x: pos) res *= x;
    for (auto x: neg) res *= -x;
    return println("{}", res.get()), 0;
  }

  if (i == nz.size()) {
    return println("0"), 0;
  }

  int64_t np = 0, nn = 0;
  for (; i < nz.size(); ++i) {
    if (np == 0 && nz[i] > 0) {
      np = nz[i];
    }
    if (nn == 0 && nz[i] < 0) {
      nn = nz[i];
    }
  }

  eprintln("np: {}", np);
  eprintln("nn: {}", nn);

  mi pre = 1;
  for (size_t i = 0; i+1 < pos.size(); ++i) pre *= pos[i];
  for (size_t i = 0; i+1 < neg.size(); ++i) pre *= neg[i];

  eprintln("pre: {}", pre.get());

  if (pos.empty()) {
    return println("{}", (pre * np).get()), 0;
  }

  int64_t suf = 0;
  if (!pos.empty()) {
    eprintln("if1 {} * {}", pos.back(), np);
    suf = std::max(suf, pos.back() * np);
  }
  if (!neg.empty()) {
    eprintln("if2 {} * {}", neg.back(), nn);
    suf = std::max(suf, neg.back() * nn);
  }

  mi res = pre * suf;

  println("{}", res.get());
}


Measured memory_bytes: 9588