import sys

input=sys.stdin.readline

mod=10**9+7

n,k=list(map(int,input().split()))

A=list(map(int,input().split()))

K=k



B,C=[],[]

for i in A:

    if i>=0:B.append(i)

    else:C.append(i)



B.sort()

C.sort(key=lambda x:abs(x))



ans,flag=1,1

while k!=0:

    if k>=2:

        point=0

        if len(B)>=2 and len(C)>=2:

            if B[-1]*B[-2]>C[-1]*C[-2]:

                ans *=B.pop()

                point=1

            else:ans *=C.pop()*C.pop()

        elif len(B)>=2:ans *=B.pop()*B.pop()

        elif len(C)>=2:ans *=C.pop()*C.pop()

        else:flag=0

        k -=2-point

    else:

        if len(B)>=1:ans *=B.pop()

        else:flag=0

        k -=1

    ans %=mod



if flag:print(ans)

else:

    ans=1

    A=sorted(A,key=lambda x:abs(x))

    for i in range(K):

        ans *=A[i]

        ans %=mod

    print(ans)
n,k=list(map(int,input().split()))

A=list(map(int,input().split()))

mod=10**9+7

count=k



B,C=[],[]

for i in A:

    if i<=0:B.append(i)

    else:C.append(i)

B.sort(key=lambda x:abs(x))

C.sort()



ans,flag=1,1

while k!=0:

    if k>=2:

        if len(B)>=2 and len(C)>=2:

            if B[-1]*B[-2]>C[-1]*C[-2]:

                ans *=B.pop()*B.pop()

                k -=2

            else:

                ans *=C.pop()

                k -=1

        elif len(B)>=2:

            ans *=B.pop()*B.pop()

            k -=2

        elif len(C)>=2:

            ans *=C.pop()*C.pop()

            k -=2

        else:flag=0;break

    else:

        if len(C)>0:

            ans *=C.pop()

            k -=1

        else:flag=0;break

    ans %=mod



if flag:print(ans)

else:

    ans=1

    A.sort(reverse=True)

    for i in range(count):

        ans *=A[i]

        ans %=mod

    print(ans)
import sys

input = sys.stdin.readline
mod = 10**9 + 7
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
K = k
B, C = [], []
for i in A:
    if i >= 0:
        B.append(i)
    else:
        C.append(i)
B.sort()
C.sort(key=lambda x: abs(x))
ans, flag = 1, 1
while k != 0:
    if k >= 2:
        point = 0
        if len(B) >= 2 and len(C) >= 2:
            if B[-1] * B[-2] > C[-1] * C[-2]:
                ans *= B.pop()
                point = 1
            else:
                ans *= C.pop() * C.pop()
        elif len(B) >= 2:
            ans *= B.pop() * B.pop()
        elif len(C) >= 2:
            ans *= C.pop() * C.pop()
        else:
            flag = 0
        k -= 2 - point
    else:
        if len(B) >= 1:
            ans *= B.pop()
        else:
            flag = 0
        k -= 1
    ans %= mod
if flag:
    print(ans)
else:
    ans = 1
    A = sorted(A, key=lambda x: abs(x))
    for i in range(K):
        ans *= A[i]
        ans %= mod
    print(ans)

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9 + 7
count = k
B, C = [], []
for i in A:
    if i <= 0:
        B.append(i)
    else:
        C.append(i)
B.sort(key=lambda x: abs(x))
C.sort()
ans, flag = 1, 1
while k != 0:
    if k >= 2:
        if len(B) >= 2 and len(C) >= 2:
            if B[-1] * B[-2] > C[-1] * C[-2]:
                ans *= B.pop() * B.pop()
                k -= 2
            else:
                ans *= C.pop()
                k -= 1
        elif len(B) >= 2:
            ans *= B.pop() * B.pop()
            k -= 2
        elif len(C) >= 2:
            ans *= C.pop() * C.pop()
            k -= 2
        else:
            flag = 0
            break
    else:
        if len(C) > 0:
            ans *= C.pop()
            k -= 1
        else:
            flag = 0
            break
    ans %= mod
if flag:
    print(ans)
else:
    ans = 1
    A.sort(reverse=True)
    for i in range(count):
        ans *= A[i]
        ans %= mod
    print(ans)

-import sys - -input = sys.stdin.readline -mod = 10**9 + 7 -K = k +mod = 10**9 + 7 +count = k -    if i >= 0: +    if i <= 0: -B.sort() -C.sort(key=lambda x: abs(x)) +B.sort(key=lambda x: abs(x)) +C.sort() -        point = 0 -                ans *= B.pop() -                point = 1 +                ans *= B.pop() * B.pop() +                k -= 2 -                ans *= C.pop() * C.pop() +                ans *= C.pop() +                k -= 1 +            k -= 2 +            k -= 2 -        k -= 2 - point +            break -        if len(B) >= 1: -            ans *= B.pop() +        if len(C) > 0: +            ans *= C.pop() +            k -= 1 -        k -= 1 +            break -    A = sorted(A, key=lambda x: abs(x)) -    for i in range(K): +    A.sort(reverse=True) +    for i in range(count):