local n,k=io.read("n","n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end
table.sort(a)
local mod=1000000007
local mul1=1
for i=1,k do
    mul1=mul1*a[i]%mod
end
local mul2=1
for i=n,n-k+1,-1 do
    mul2=mul2*a[i]%mod
end
print(math.max(mul1,mul2))