# import time
# t1=time.time()
def LI():return list(map(int,input().split()))
def I(): return int(input())
from collections import deque, Counter, defaultdict
# from heapq import heappop, heappush
# from pprint import pprint
# import numpy as np
# import itertools

MOD=10**9+7

n,k=LI()
a=LI()
if k==1:
    a.sort()
    print(a[-1]%MOD)
    exit()
if n==k:
    ans=1
    for i in range(k):
        ans=ans*a[i]%MOD
    print(ans)
    exit()
    
# minus=[]
# plus=[]
# for q in a:
#     if q>=0:
#         plus.append(q)
#     else:
#         minus.append(q)
# if len(plus)==n:
#     plus.sort(reverse=True)
#     ans=1
#     for i in range(k):
#         ans=ans*plus[i]%MOD
#     print(ans)
#     exit()
    
# if len(minus)==n:
#     if k%2==0:
#         minus.sort()
#         ans=1
#         for i in range(k):
#             ans=ans*minus[i]%MOD
#         print(ans)
#         exit()
#     else:
#         minus.sort(reverse=True)
#         ans=1
#         for i in range(k):
#             ans=ans*minus[i]%MOD
#         print(ans)
#         exit()
      
# if k%2==0:
#     if len(minus)==1:
#         plus.sort(reverse=True)
#         ans=1
#         for i in range(k):
#             ans=ans*plus[i]%MOD
#         print(ans)
#         exit()
#     if len(minus)>=2:
#         minus.sort()
#         minus=deque(minus)
#         while True:
#             if len(minus)<=1:
#                 break
#             if k==1:
#                 break
#             a=minus.popleft()
#             b=minus.popleft()
#             plus.append(a*b)
#             k-=1
            
#     plus.sort(reverse=True)
#     ans=1
#     for i in range(k):
#         ans=ans*plus[i]%MOD
#     print(ans)
#     exit()

# if k%2==1:
#     if len(minus)==1:
#         if k<=len(plus):
#             ans=1
#             plus.sort(reverse=True)
#             for i in range(k):
#                 ans=ans*plus[i]%MOD
#             print(ans)
#             exit()
#         else:
#             ans=1
#             ans=ans*minus[0]
#             plus.sort()
#             for i in range(k-1):
#                 ans=ans*plus[i]%MOD
#             print(ans)
#             exit()
#     else:
#         minus.sort()
#         minus=deque(minus)
#         while True:
#             if len(minus)<=1:
#                 break
#             if k==1:
#                 break
#             a=minus.popleft()
#             b=minus.popleft()
#             plus.append(a*b)
#             k-=1
            
#     plus.sort(reverse=True)
#     ans=1
#     for i in range(k):
#         ans=ans*plus[i]%MOD
#     print(ans)
#     exit()
    
    
for q in a:
    b.append(q%MOD)
b.sort(reverse=True)

ans=1
for i in range(k):
    ans=ans*b[i]%MOD
print(ans)



### FIXED CODE ###

import sys

# after これ通る？コピペs


def solve(n, k, aaa):
    MOD = 10 ** 9 + 7

    if n == k:
        ans = 1
        for a in aaa:
            ans = ans * a % MOD
        return ans

    pos = []  # Strictly, Non-neg
    neg = []
    for a in aaa:
        if a >= 0:
            pos.append(a)
        elif a < 0:
            neg.append(a)

    if len(pos) == 0:
        if k % 2 == 1:
            neg.sort(reverse=True)
        else:
            neg.sort()
        ans = 1
        for a in neg[:k]:
            ans = ans * a % MOD
        return ans

    pos.sort()
    neg.sort(reverse=True)
    ans = 1
    r = k

    if r % 2 == 1:
        ans = ans * pos.pop() % MOD
        r -= 1

    while r > 0:
        if len(pos) <= 1:
            ans = ans * neg.pop() * neg.pop() % MOD
        elif len(neg) <= 1:
            ans = ans * pos.pop() * pos.pop() % MOD
        else:
            pm = pos[-1] * pos[-2]
            nm = neg[-1] * neg[-2]
            if pm > nm:
                ans = ans * pos.pop() * pos.pop() % MOD
            else:
                ans = ans * neg.pop() * neg.pop() % MOD
        r -= 2

    return ans


n, k, *aaa = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, aaa))