import sys

input = sys.stdin.readline



N, K = list(map(int, input().split()))

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

MOD = 10**9+7

p, n = [], []



for i in range(N):

    if A[i]>=0:

        p.append(A[i])

    else:

        n.append(A[i])



ok = False



if len(p)>0:

    if N==K:

        if len(n)%2==0:

            ok = True

    else:

        ok = True

else:

    if K%2==0:

        ok = True



if not ok:

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

    ans = 1

    

    for Ai in A[:K]:

        ans *= Ai

        ans %= MOD



    print(ans)

    exit()



p.sort(reverse=True)

n.sort()



if K%2==1:

    ans = p[0]

    p = p[1:]

else:

    ans = 1

    

l = []

    

for i in range(len(p)//2):

    l.append(p[2*i]*p[2*i+1])

    

for i in range(len(n)//2):

    l.append(n[2*i]*n[2*i+1])



l.sort(key=lambda x: abs(x), reverse=True)



for li in l[:K//2]:

    ans *= li

    ans %= MOD

    

print(ans)

import sys

input = sys.stdin.readline

from collections import *



N, K = list(map(int, input().split()))

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

MOD = 10**9+7

p, n = [], []



for Ai in A:

    if Ai>=0:

        p.append(Ai)

    else:

        n.append(Ai)



if len(p)==0 and K%2==1:

    if 0 in A:

        print((0))

    else:

        n.sort(reverse=True)

        ans = 1

        

        for ni in n[:K]:

            ans *= ni

            ans %= MOD

        

        print(ans)

    exit()

    

if K==N:

    ans = 1

    

    for Ai in A:

        ans *= Ai

        ans %= MOD

    

    print(ans)

    exit()



p.sort(reverse=True)

n.sort()



if K%2==0:

    l = []

    

    for i in range(len(p)//2):

        l.append(p[2*i]*p[2*i+1])

    

    for i in range(len(n)//2):

        l.append(n[2*i]*n[2*i+1])



    l.sort(key=lambda x: abs(x), reverse=True)

    ans = 1

    

    for i in range(K//2):

        ans *= l[i]

        ans %= MOD

else:

    ans = p[0]

    p = p[1:]

    l = []

    

    for i in range(len(p)//2):

        l.append(p[2*i]*p[2*i+1])

    

    for i in range(len(n)//2):

        l.append(n[2*i]*n[2*i+1])

    

    l.sort(key=lambda x: abs(x), reverse=True)

    

    for i in range((K-1)//2):

        ans *= l[i]

        ans %= MOD



print(ans)

import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
p, n = [], []
for i in range(N):
    if A[i] >= 0:
        p.append(A[i])
    else:
        n.append(A[i])
ok = False
if len(p) > 0:
    if N == K:
        if len(n) % 2 == 0:
            ok = True
    else:
        ok = True
else:
    if K % 2 == 0:
        ok = True
if not ok:
    A.sort(key=lambda x: abs(x))
    ans = 1
    for Ai in A[:K]:
        ans *= Ai
        ans %= MOD
    print(ans)
    exit()
p.sort(reverse=True)
n.sort()
if K % 2 == 1:
    ans = p[0]
    p = p[1:]
else:
    ans = 1
l = []
for i in range(len(p) // 2):
    l.append(p[2 * i] * p[2 * i + 1])
for i in range(len(n) // 2):
    l.append(n[2 * i] * n[2 * i + 1])
l.sort(key=lambda x: abs(x), reverse=True)
for li in l[: K // 2]:
    ans *= li
    ans %= MOD
print(ans)

import sys

input = sys.stdin.readline
from collections import *

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
p, n = [], []
for Ai in A:
    if Ai >= 0:
        p.append(Ai)
    else:
        n.append(Ai)
if len(p) == 0 and K % 2 == 1:
    if 0 in A:
        print((0))
    else:
        n.sort(reverse=True)
        ans = 1
        for ni in n[:K]:
            ans *= ni
            ans %= MOD
        print(ans)
    exit()
if K == N:
    ans = 1
    for Ai in A:
        ans *= Ai
        ans %= MOD
    print(ans)
    exit()
p.sort(reverse=True)
n.sort()
if K % 2 == 0:
    l = []
    for i in range(len(p) // 2):
        l.append(p[2 * i] * p[2 * i + 1])
    for i in range(len(n) // 2):
        l.append(n[2 * i] * n[2 * i + 1])
    l.sort(key=lambda x: abs(x), reverse=True)
    ans = 1
    for i in range(K // 2):
        ans *= l[i]
        ans %= MOD
else:
    ans = p[0]
    p = p[1:]
    l = []
    for i in range(len(p) // 2):
        l.append(p[2 * i] * p[2 * i + 1])
    for i in range(len(n) // 2):
        l.append(n[2 * i] * n[2 * i + 1])
    l.sort(key=lambda x: abs(x), reverse=True)
    for i in range((K - 1) // 2):
        ans *= l[i]
        ans %= MOD
print(ans)

+from collections import * + -for i in range(N): -    if A[i] >= 0: -        p.append(A[i]) +for Ai in A: +    if Ai >= 0: +        p.append(Ai) -        n.append(A[i]) -ok = False -if len(p) > 0: -    if N == K: -        if len(n) % 2 == 0: -            ok = True +        n.append(Ai) +if len(p) == 0 and K % 2 == 1: +    if 0 in A: +        print((0)) -        ok = True -else: -    if K % 2 == 0: -        ok = True -if not ok: -    A.sort(key=lambda x: abs(x)) +        n.sort(reverse=True) +        ans = 1 +        for ni in n[:K]: +            ans *= ni +            ans %= MOD +        print(ans) +    exit() +if K == N: -    for Ai in A[:K]: +    for Ai in A: -if K % 2 == 1: +if K % 2 == 0: +    l = [] +    for i in range(len(p) // 2): +        l.append(p[2 * i] * p[2 * i + 1]) +    for i in range(len(n) // 2): +        l.append(n[2 * i] * n[2 * i + 1]) +    l.sort(key=lambda x: abs(x), reverse=True) +    ans = 1 +    for i in range(K // 2): +        ans *= l[i] +        ans %= MOD +else: -else: -    ans = 1 -l = [] -for i in range(len(p) // 2): -    l.append(p[2 * i] * p[2 * i + 1]) -for i in range(len(n) // 2): -    l.append(n[2 * i] * n[2 * i + 1]) -l.sort(key=lambda x: abs(x), reverse=True) -for li in l[: K // 2]: -    ans *= li -    ans %= MOD +    l = [] +    for i in range(len(p) // 2): +        l.append(p[2 * i] * p[2 * i + 1]) +    for i in range(len(n) // 2): +        l.append(n[2 * i] * n[2 * i + 1]) +    l.sort(key=lambda x: abs(x), reverse=True) +    for i in range((K - 1) // 2): +        ans *= l[i] +        ans %= MOD