import kotlin.math.absoluteValue

private const val MOD = 1_000_000_007

fun main() {
    val (n, k) = nextIntList()
    val nums = nextLongList().groupBy { it >= 0 }.mapValues { (_, value) ->
        value.sortedByDescending { it.absoluteValue }
    }
    val positives = nums.getOrDefault(true, emptyList())
    val negatives = nums.getOrDefault(false, emptyList())
    var posIndex = 0
    var negIndex = 0
    val res = mutableListOf<Long>()
    when {
        n == k -> {
            res.addAll(positives)
            res.addAll(negatives)
        }
        positives.isEmpty() && k % 2 == 1 -> res.addAll(negatives.sortedDescending().take(k))
        else -> while (res.size < k) {
            when {
                res.size == k - 1 -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                negIndex >= negatives.lastIndex -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                posIndex >= positives.lastIndex -> {
                    res.add(negatives[negIndex])
                    res.add(negatives[negIndex + 1])
                    negIndex += 2
                }
                positives[posIndex] * positives[posIndex + 1] > negatives[negIndex] * negatives[negIndex + 1] -> {
                    res.add(positives[posIndex])
                    posIndex++
                }
                else -> {
                    res.add(negatives[negIndex])
                    res.add(negatives[negIndex + 1])
                    negIndex += 2
                }
            }
        }
    }
    println(res.stream().map { it.plus(MOD).rem(MOD) }.reduce { acc, l -> acc.times(l).rem(MOD) }.get())
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}
