import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val K = sc.next().toInt()
        val A = LongArray(N) { sc.next().toLong() }

        val AP = A.filter { it > 0 }.sortedBy { -it }.toLongArray() // positive
        val AN = A.filter { it <= 0 }.sorted().toLongArray() // negative
        val CN = AN.count()

        var ans = 1L

        var kp = min(K, AP.count())
        var kn = K - kp
        if (kn % 2 == 1) {
            //dprint("kp=$kp kn=$kn")
            //if (kp == 0 || kn + 1 > CN) {
            if (kp == 0) {
                // マイナスしかできないので絶対値の小さいほうから K 個
                AN.reversed().take(K).forEach {
                    ans *= it
                    ans += 1000000007L
                    ans %= 1000000007L
                }
                pw.println(ans)
                return
            } else if (K == N) {
                // すべて選ぶしかない
                A.forEach {
                    ans *= it
                    ans += 1000000007L
                    ans %= 1000000007L
                }
                pw.println(ans)
                return
            }
            kp--
            kn++
        }

        while (true) {
            //dprint("kp=$kp kn=$kn")
            if (kp < 2 || kn + 2 > CN) break
            val a1 = AP[kp - 2] * AP[kp - 1]
            val a2 = AN[kn] * AN[kn + 1]
            if (a1 > a2) break
            kp -= 2
            kn += 2
        }

        for (i in 0 until kp) {
            ans *= AP[i]
            ans %= 1000000007L
        }
        for (i in 0 until kn) {
            ans *= -AN[i]
            ans %= 1000000007L
        }
        pw.println(ans)
    }
}
