import kotlin.math.abs

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(' ').map { it.toInt() }
    val A = readLine()!!.split(' ').map { it.toLong() }
    val positiveA = A.filter { it >= 0 }.sortedDescending()
    val negativeA = A.filter { it < 0 }.sorted()

    if (N == K) {
        println(A.reduce { acc, l -> mul(acc, l) })
        return
    }
    if (positiveA.isEmpty() && K % 2 == 1) {
        println(negativeA.takeLast(K).reduce { acc, l -> mul(acc, l) })
        return
    }

    var positiveIdx = 0
    var negativeIdx = 0
    var ans = 1L
    var remK = K

    while (remK > 0) {
        if (remK == 1) {
            ans = mul(ans, positiveA[positiveIdx])
            break
        }

        val positiveX = if (positiveA.size - positiveIdx >= 2) {
            positiveA[positiveIdx] * positiveA[positiveIdx + 1]
        } else {
            0L
        }
        val negativeX = if (negativeA.size - negativeIdx >= 2) {
            negativeA[negativeIdx] * negativeA[negativeIdx + 1]
        } else {
            0L
        }

        if (positiveX >= negativeX) {
            ans = mul(ans, positiveA[positiveIdx])
            positiveIdx++
            remK--
        } else {
            ans = mul(ans, negativeA[negativeIdx])
            ans = mul(ans, negativeA[negativeIdx + 1])
            negativeIdx += 2
            remK -= 2
        }
    }

    println(ans)
}

fun mul(x: Long, y: Long): Long {
    val mod = 1000000007L
    return ((x * y) + mod * mod) % mod
}