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 == n) return println(aList.fold(Mint(1), Mint::times))

    val (positives, negatives) = aList
        .sortedByDescending { abs(it) }.partition { it > 0 }.toList().map { ArrayDeque(it) }

    var answer = Mint(1)

    if (k % 2 != 0) {
        if (positives.isEmpty()) return println(negatives.takeLast(k).fold(Mint(1), Mint::times))
        else answer *= positives.removeFirst()
    }

    repeat(k / 2) {
        when {
            positives.size >= 2 && negatives.size >= 2 -> {
                val pos = positives.take(2).reduce(Long::times)
                val neg = negatives.take(2).reduce(Long::times)
                if (pos > neg) {
                    answer *= pos
                    repeat(2) { positives.removeFirst() }
                } else {
                    answer *= neg
                    repeat(2) { negatives.removeFirst() }
                }
            }
            positives.size >= 2 -> answer *= positives.removeFirst() * positives.removeFirst()
            negatives.size >= 2 -> answer *= negatives.removeFirst() * negatives.removeFirst()
            else -> error("なんで？")
        }
    }

    println(answer)
}

private const val MOD = 1_000_000_007L

@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 * Mint(other).value)
    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
        }
    }
}
