import kotlin.math.abs

fun main() = Thread(null, ::abc173e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173e() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    if (k == 1) return println(aList.max()!!)
    if (n == k) return println(aList.fold(Mint(1), Mint::times))

    val sortedByAbsDesc = aList.sortedByDescending { abs(it) }
    val take = sortedByAbsDesc.take(k)
    val (takePos, takeNeg) = take.partition { it >= 0 }

    if (take.contains(0)) return println(0)

    val rem = sortedByAbsDesc.drop(k)
    val (remPos, remNeg) = rem.partition { it >= 0 }

    val fold = take.fold(Mint(1), Mint::times)

    val answer = if (take.count { it < 0 } % 2 == 0) {
        fold
    } else {
        val takeHavePos = take.count { it >= 0 } > 0
        val takeHaveNeg = take.count { it < 0 } > 0
        val remAHavePos = rem.count { it >= 0 } > 0
        val remAHaveNeg = rem.count { it < 0 } > 0
        if (takeHavePos && takeHaveNeg && remAHavePos && remAHaveNeg) {
            if (takeNeg.max()!! * remNeg.min()!! > takePos.min()!! * remPos.max()!!) {
                fold / takePos.min()!! * remNeg.min()!!
            } else {
                fold / takeNeg.max()!! * remPos.max()!!
            }
        } else if (takeHavePos && remAHaveNeg) {
            fold / takePos.min()!! * remNeg.min()!!
        } else if (takeHaveNeg && remAHavePos) {
            fold / takeNeg.max()!! * remPos.max()!!
        } else {
            val takeLast = sortedByAbsDesc.filter { it < 0 }.takeLast(k)
            if (takeLast.size == k) takeLast.fold(Mint(1), Mint::times) else Mint(0)
        }
    }

    println(answer)
}

private const val MOD = 1_000_000_007L
private fun Long.toMint() = Mint(this)
private fun Int.toMint() = Mint(this.toLong())

@Suppress("unused")
private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * other)
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2))
    operator fun div(other: Mint) = this.div(other.value)
    fun mod(mod: Long) = Mint(this.value % mod)
    fun modPow(other: Long) = Mint(modPow(this.value, other))
    fun toLong() = this.value
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object {
        private fun modPow(n: Long, p: Long): Long {
            var x = n % MOD
            var y = p
            var result = 1L
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % MOD
                y = y shr 1
                x = (x * x) % MOD
            }
            return result
        }
    }
}
