const input = require("fs").readFileSync("/dev/stdin", "utf8")

const mod = 1000000007
function mul (a, b) {
    return ((a >> 16) * b % mod * 65536 + (a & 65535) * b) % mod
}

;(input => {

    const lines = input.split('\n')
    const [N, K] = lines[0].split(" ").map(Number)
    const A = lines[1].split(" ").map(Number)

    A.sort((a, b) => Math.abs(b) - Math.abs(a))

    let sign = 0
    let last = 0
    let p = 1
    for (let i = 0; i < K; i++) {
        if (A[i] < 0) {
            sign++
            last = i
        }
        p = mul(p, A[i])
    }
    if (sign > N - K && K % 2) {
        p = 1
        for (let i = N - 1; i >= N - K; i--) {
            p = mul(p, A[i])
            p = (p*mod<0)*mod+p%mod
        }
    } else if (p < 0) {
       p /= A[last]
       for (let i = K; i < N; i++) {
           if (A[i] >= 0) {
               p = mul(p, A[i])
               break
           }
       }
    }

    console.log(p)

})(input)
