object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val a = Array.fill(n)(sc.nextLong())

  val mod = 1000000007

  def minus(a: Long, b: Long): Long = (a - b + mod) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  val b = a.filter(_ != 0).map(e => (e.abs, e)).sorted
  if (b.length < k) {
    println(0)
  } else if (b.length == k) {
    if (b.count(_._2 < 0) % 2 == 0) {
      println(b.map(_._1).reduceLeft(times))
    } else {
      if (a.contains(0)) {
        println(0)
      } else {
        println(minus(0, b.map(_._1).reduceLeft(times)))
      }
    }
  } else {
    if (b.forall(_._2 > 0)) {
      println(b.takeRight(k).map(_._1).reduceLeft(times))
    } else if (b.forall(_._2 < 0)) {
      if (k % 2 == 0) {
        println(b.takeRight(k).map(_._1).reduceLeft(times))
      } else {
        if (a.contains(0)) {
          println(0)
        } else {
          println(minus(0, b.take(k).map(_._1).reduceLeft(times)))
        }
      }
    } else {
      val (r, c) = b.splitAt(b.length - k)
      if (c.count(_._2 < 0) % 2 == 0) {
        println(c.map(_._1).reduceLeft(times))
      } else {
        val pf = c.indexWhere(_._2 > 0)
        val mf = c.indexWhere(_._2 < 0)
        if (pf == -1) {
          c(mf) = r.findLast(_._2 > 0).get
        } else {
          val ml = r.findLast(_._2 < 0)
          val pl = r.findLast(_._2 > 0)

          if (ml.isEmpty) {
            c(mf) = pl.get
          } else if (pl.isEmpty) {
            c(pf) = ml.get
          } else {
            if (c(pf)._1 * pl.get._1 < c(mf)._1 * ml.get._1) {
              c(pf) = ml.get
            } else {
              c(mf) = pl.get
            }
          }
        }
        println(c.map(_._1).reduceLeft(times))
      }
    }
  }
}
