MOD = (10 ** 9) + 7

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

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

 

negs = [-x for x in a if x < 0]

non_negs = [x for x in a if x >= 0]

 

if len(non_negs) == 0 and k % 2 == 1:

    negs.sort()

    ans = 1

    for i in range(k):

        ans = ans * -negs[i] % MOD

    print(ans)

    exit()

 

negs_p, non_negs_p = 0, 0

 

negs.sort(reverse = True)

non_negs.sort(reverse = True)

 

for i in range(k):

    if negs_p == len(negs):

        non_negs_p += 1

    elif non_negs_p == len(non_negs):

        negs_p += 1

    elif negs[negs_p] > non_negs[non_negs_p]:

        negs_p += 1

    else:

        non_negs_p += 1

 

if negs_p % 2 == 0 or k == n:

    ans = 1

    for i in range(negs_p):

        ans = ans * -negs[i] % MOD

    for i in range(non_negs_p):

        ans = ans * non_negs[i] % MOD

    print(ans)

    exit()

 

if negs_p == len(negs) or non_negs_p == 0:

    negs_p -= 1

    non_negs_p += 1

    ans = 1

    for i in range(negs_p):

        ans = ans * -negs[i] % MOD

    for i in range(non_negs_p):

        ans = ans * non_negs[i] % MOD

    print(ans)

    exit()

 

if non_negs_p == len(non_negs) or negs_p == 0:

    negs_p += 1

    non_negs_p -= 1

    ans = 1

    for i in range(negs_p):

        ans = ans * -negs[i] % MOD

    for i in range(non_negs_p):

        ans = ans * non_negs[i] % MOD

    print(ans)

    exit()

 

 

a = negs[negs_p - 1]

b = negs[negs_p]

c = non_negs[non_negs_p - 1]

d = non_negs[non_negs_p]

 

if a * b > c * d:

    negs_p += 1

    non_negs_p -= 1

else:

    negs_p -= 1

    non_negs_p += 1

 

ans = 1

for i in range(negs_p):

    ans = ans * -negs[i] % MOD

for i in range(non_negs_p):

    ans = ans * non_negs[i] % MOD

print(ans)
import sys 

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

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

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

MOD = 10**9 +7

B = []

C = []

for a in A:

    if a >= 0:

        B.append(a)

    else:

        C.append(-a)



ans = 1

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

    C = sorted(C)

    for i in range(K):

        ans *= -C[i]

        ans %= MOD

    print(ans)

    sys.exit()

      

negs_p = 0

non_negs_p = 0

B = sorted(B,reverse = True)

C = sorted(C,reverse = True)



for i in range(K):

    if negs_p == len(C):

        non_negs_p += 1

    elif non_negs_p == len(B):

        negs_p += 1

    elif C[negs_p] > B[non_negs_p]:

        negs_p += 1

    else:

        non_negs_p += 1

        

if N == K or negs_p % 2 == 0:

    for i in range(non_negs_p):

        ans = ans * B[i] % MOD

    for i in range(negs_p):

        ans = ans * -C[i] % MOD

    print(ans)

    sys.exit()



if negs_p % 2 == 1:

    if negs_p == len(C) or non_negs_p == 0:

        negs_p -= 1

        non_negs_p += 1 

        for i in range(non_negs_p):

            ans = ans * B[i] % MOD

        for i in range(negs_p):

            ans = ans * -C[i] % MOD

    elif non_negs_p == len(B) or negs_p == 0:

        negs_p += 1

        non_negs_p -= 1 

        for i in range(non_negs_p):

            ans = ans * B[i] % MOD

        for i in range(negs_p):

            ans = ans * -C[i] % MOD

    else:

        a,b,c,d = C[negs_p],C[negs_p-1],B[non_negs_p],B[non_negs_p-1]

        if a*b > c*d:

            negs_p += 1

            non_negs_p -= 1

        else:   

            negs_p -= 1

            non_negs_p += 1

        for i in range(non_negs_p):

            ans = ans * B[i] % MOD

        for i in range(negs_p):

            ans = ans * -C[i] % MOD

print(ans) 

    

    

    

        

        

        
MOD = (10**9) + 7
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
negs = [-x for x in a if x < 0]
non_negs = [x for x in a if x >= 0]
if len(non_negs) == 0 and k % 2 == 1:
    negs.sort()
    ans = 1
    for i in range(k):
        ans = ans * -negs[i] % MOD
    print(ans)
    exit()
negs_p, non_negs_p = 0, 0
negs.sort(reverse=True)
non_negs.sort(reverse=True)
for i in range(k):
    if negs_p == len(negs):
        non_negs_p += 1
    elif non_negs_p == len(non_negs):
        negs_p += 1
    elif negs[negs_p] > non_negs[non_negs_p]:
        negs_p += 1
    else:
        non_negs_p += 1
if negs_p % 2 == 0 or k == n:
    ans = 1
    for i in range(negs_p):
        ans = ans * -negs[i] % MOD
    for i in range(non_negs_p):
        ans = ans * non_negs[i] % MOD
    print(ans)
    exit()
if negs_p == len(negs) or non_negs_p == 0:
    negs_p -= 1
    non_negs_p += 1
    ans = 1
    for i in range(negs_p):
        ans = ans * -negs[i] % MOD
    for i in range(non_negs_p):
        ans = ans * non_negs[i] % MOD
    print(ans)
    exit()
if non_negs_p == len(non_negs) or negs_p == 0:
    negs_p += 1
    non_negs_p -= 1
    ans = 1
    for i in range(negs_p):
        ans = ans * -negs[i] % MOD
    for i in range(non_negs_p):
        ans = ans * non_negs[i] % MOD
    print(ans)
    exit()
a = negs[negs_p - 1]
b = negs[negs_p]
c = non_negs[non_negs_p - 1]
d = non_negs[non_negs_p]
if a * b > c * d:
    negs_p += 1
    non_negs_p -= 1
else:
    negs_p -= 1
    non_negs_p += 1
ans = 1
for i in range(negs_p):
    ans = ans * -negs[i] % MOD
for i in range(non_negs_p):
    ans = ans * non_negs[i] % MOD
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
MOD = 10**9 + 7
B = []
C = []
for a in A:
    if a >= 0:
        B.append(a)
    else:
        C.append(-a)
ans = 1
if len(B) == 0 and K % 2 == 1:
    C = sorted(C)
    for i in range(K):
        ans *= -C[i]
        ans %= MOD
    print(ans)
    sys.exit()
negs_p = 0
non_negs_p = 0
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
for i in range(K):
    if negs_p == len(C):
        non_negs_p += 1
    elif non_negs_p == len(B):
        negs_p += 1
    elif C[negs_p] > B[non_negs_p]:
        negs_p += 1
    else:
        non_negs_p += 1
if N == K or negs_p % 2 == 0:
    for i in range(non_negs_p):
        ans = ans * B[i] % MOD
    for i in range(negs_p):
        ans = ans * -C[i] % MOD
    print(ans)
    sys.exit()
if negs_p % 2 == 1:
    if negs_p == len(C) or non_negs_p == 0:
        negs_p -= 1
        non_negs_p += 1
        for i in range(non_negs_p):
            ans = ans * B[i] % MOD
        for i in range(negs_p):
            ans = ans * -C[i] % MOD
    elif non_negs_p == len(B) or negs_p == 0:
        negs_p += 1
        non_negs_p -= 1
        for i in range(non_negs_p):
            ans = ans * B[i] % MOD
        for i in range(negs_p):
            ans = ans * -C[i] % MOD
    else:
        a, b, c, d = C[negs_p], C[negs_p - 1], B[non_negs_p], B[non_negs_p - 1]
        if a * b > c * d:
            negs_p += 1
            non_negs_p -= 1
        else:
            negs_p -= 1
            non_negs_p += 1
        for i in range(non_negs_p):
            ans = ans * B[i] % MOD
        for i in range(negs_p):
            ans = ans * -C[i] % MOD
print(ans)

-MOD = (10**9) + 7 -n, k = list(map(int, input().split())) -a = list(map(int, input().split())) -negs = [-x for x in a if x < 0] -non_negs = [x for x in a if x >= 0] -if len(non_negs) == 0 and k % 2 == 1: -    negs.sort() -    ans = 1 -    for i in range(k): -        ans = ans * -negs[i] % MOD +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N, K = list(map(int, readline().split())) +A = list(map(int, readline().split())) +MOD = 10**9 + 7 +B = [] +C = [] +for a in A: +    if a >= 0: +        B.append(a) +    else: +        C.append(-a) +ans = 1 +if len(B) == 0 and K % 2 == 1: +    C = sorted(C) +    for i in range(K): +        ans *= -C[i] +        ans %= MOD -    exit() -negs_p, non_negs_p = 0, 0 -negs.sort(reverse=True) -non_negs.sort(reverse=True) -for i in range(k): -    if negs_p == len(negs): +    sys.exit() +negs_p = 0 +non_negs_p = 0 +B = sorted(B, reverse=True) +C = sorted(C, reverse=True) +for i in range(K): +    if negs_p == len(C): -    elif non_negs_p == len(non_negs): +    elif non_negs_p == len(B): -    elif negs[negs_p] > non_negs[non_negs_p]: +    elif C[negs_p] > B[non_negs_p]: -if negs_p % 2 == 0 or k == n: -    ans = 1 +if N == K or negs_p % 2 == 0: +    for i in range(non_negs_p): +        ans = ans * B[i] % MOD -        ans = ans * -negs[i] % MOD -    for i in range(non_negs_p): -        ans = ans * non_negs[i] % MOD +        ans = ans * -C[i] % MOD -    exit() -if negs_p == len(negs) or non_negs_p == 0: -    negs_p -= 1 -    non_negs_p += 1 -    ans = 1 -    for i in range(negs_p): -        ans = ans * -negs[i] % MOD -    for i in range(non_negs_p): -        ans = ans * non_negs[i] % MOD -    print(ans) -    exit() -if non_negs_p == len(non_negs) or negs_p == 0: -    negs_p += 1 -    non_negs_p -= 1 -    ans = 1 -    for i in range(negs_p): -        ans = ans * -negs[i] % MOD -    for i in range(non_negs_p): -        ans = ans * non_negs[i] % MOD -    print(ans) -    exit() -a = negs[negs_p - 1] -b = negs[negs_p] -c = non_negs[non_negs_p - 1] -d = non_negs[non_negs_p] -if a * b > c * d: -    negs_p += 1 -    non_negs_p -= 1 -else: -    negs_p -= 1 -    non_negs_p += 1 -ans = 1 -for i in range(negs_p): -    ans = ans * -negs[i] % MOD -for i in range(non_negs_p): -    ans = ans * non_negs[i] % MOD +    sys.exit() +if negs_p % 2 == 1: +    if negs_p == len(C) or non_negs_p == 0: +        negs_p -= 1 +        non_negs_p += 1 +        for i in range(non_negs_p): +            ans = ans * B[i] % MOD +        for i in range(negs_p): +            ans = ans * -C[i] % MOD +    elif non_negs_p == len(B) or negs_p == 0: +        negs_p += 1 +        non_negs_p -= 1 +        for i in range(non_negs_p): +            ans = ans * B[i] % MOD +        for i in range(negs_p): +            ans = ans * -C[i] % MOD +    else: +        a, b, c, d = C[negs_p], C[negs_p - 1], B[non_negs_p], B[non_negs_p - 1] +        if a * b > c * d: +            negs_p += 1 +            non_negs_p -= 1 +        else: +            negs_p -= 1 +            non_negs_p += 1 +        for i in range(non_negs_p): +            ans = ans * B[i] % MOD +        for i in range(negs_p): +            ans = ans * -C[i] % MOD