const [nk, as] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
const [n, k] = nk.split(/\s/).map(Number)
const arr = as.split(/\s/).map(Number).sort((a, b) => Math.abs(b) - Math.abs(a))
const base = Math.pow(10, 9) + 7

let result = 1, lowestP = Number.POSITIVE_INFINITY, lowestN = Number.POSITIVE_INFINITY

for (let i = 0; i < k; i++) {
  result *= arr[i]
  if (arr[i] < 0) {
    lowestN = arr[i]
  } else {
    lowestP = arr[i]
  }
}
if (result < 0) {
  let result1 = result / lowestP
  let result2 = result / lowestN
  let result1Got = false
  let result2Got = false
  for (let i = k; i < n; i++) {
    if (arr[i] < 0 && !result1Got) {
      result1 *= arr[i]
    } else if (arr[i] > 0 && !result2Got) {
      result2 *= arr[i]
    }
    if ((result1Got || result1 === 0) && (result2Got || result2 === 0)) {
      break
    }
  }
  result = Math.max(result1 * Number(result1Got), result2 * Number(result2Got))
}
if (result === 0) {
  result = 1
  for (let i = n - 1; i >= n - k; i--) {
    result *= arr[i]
  }
  while (result < 0) {
    result += base
  }
  console.log(result)
} else {
  console.log(result % base)
}