function rl()
   local r = {}
   for word in io.read():gmatch("%S+") do
      table.insert(r, tonumber(word))
   end
   return r
end

function ru()
   return unpack(rl())
end

function pu(x, ...)
   if x then
      io.write(x, ' ')
      return pu(...)
   else
      io.write('\n')
   end
end

MOD = 1000000007
N, K = ru()
A = rl()

function comp(x, y)
   return math.abs(x) < math.abs(y)
end

all_negative = true
zeros = 0
for _, x in ipairs(A) do
   if x > 0 then
      all_negative = false
   elseif x == 0 then
      zeros = zeros + 1
   end
end

table.sort(A, comp)

r = 1
if zeros > N - K then
   r = 0
elseif all_negative and math.fmod(K, 2) == 1 then
   for i = zeros + 1, zeros + K do
      r = math.fmod(-r * A[i], MOD)
   end
   r = MOD - r
else
   k = 0
   sign = 1
   for i = N, 1, -1 do
      if k < K - 1 or k < K and sign * A[i] > 0 then
	 k = k + 1
	 r = math.fmod(r * math.abs(A[i]), MOD)
	 if A[i] < 0 then
	    sign = -sign
	 end
      end
      if k >= K then
	 break
      end
   end
end

pu(r)
