let mod = 1000000007
func solve(_ N: Int, _ K: Int, _ positives: [Int], _ negatives: [Int]) -> Int {
	if N == K {
      return (positives + negatives).reduce(1) { 
        $0 * $1 % mod
      }
    }
  	if negatives.isEmpty {
      return positives.prefix(K).reduce(1) { $0 * $1 % mod }
    } else if positives.isEmpty {
      if K & 1 == 0 {
        return negatives.suffix(K).reduce(1) { $0 * $1 % mod }
      } else {
        return negatives.prefix(K).reduce(1) { $0 * $1 % mod }
      }
    }
  	var i = 0
  	var j = negatives.count - 1
  	var current = 1
  	var K = K
  	if K & 1 == 1 {
      current = current * positives[i]
      i += 1
      K -= 1
    }
  	while K > 0 {
      if i >= positives.count - 1 {
        current = current * negatives[j] % mod
        current = current * negatives[j - 1] % mod
        j -= 2
      } else if j <= 0 {
        current = current * positives[i] % mod
        current = current * positives[i + 1] % mod
        i += 2
      } else if positives[i] * positives[i + 1] < negatives[j] * negatives[j - 1] {
        current = current * negatives[j] % mod
        current = current * negatives[j - 1] % mod
        j -= 2
      } else {
        current = current * positives[i] % mod
        current = current * positives[i + 1] % mod
        i += 2
      }
      K -= 2
    }
  	return current
}

let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let K = input[1]

let values = readLine()!.split(separator: " ").map { Int($0)! }

var positives: [Int] = []
var negatives: [Int] = []

for v in values {
  if v < 0 {
    negatives.append(v)
  } else {
    positives.append(v)
  }
}

positives = Array(positives.sorted().reversed())
negatives = Array(negatives.sorted().reversed())

let res = solve(N, K, positives, negatives)
print(res < 0 ? mod + res : res)