x = list(input().split())
a = list((int(i) for i in input().split()))
n, k = int(x[0]), int(x[1])
#import random
#n = random.choice(range(10000))
#k = random.choice(range(n))
#a = random.choices(range(-1000000, 1000000, 1), k=n)
#print('n =', n, 'k =', k)

MOD = 10**9 + 7

a_abs = []
for i in range(len(a)): a_abs.append(abs(a[i]))

res = sorted(list(zip(a_abs, a)))
val = []
for i in range(len(res)): val.append(res.pop()[1])

# check negative mode
signA, signB, neg = True, False, False
for i in range(len(val)):
    if val[i] < 0:
        signA = not signA
    else:
        signB = True
if (n==k and not signA) or (not signB):
    neg = True # answer will be negative

index_replaced, index_replace = None, None
index_replaced_a, index_replace_a = None, None
if (not neg): # positive
    # take top k
    ans = val[0:k]
    sign = True
    for i in range(len(ans)):
        if ans[i] < 0:
            sign = not sign
            
    # replace if necessary
    if (not sign):
        # find smallest negative
        for i in range(len(ans), 0, -1):
            if ans[i-1] < 0:
                index_replaced = i-1
                break
        # find largest positive
        for i in range(k, len(val)):
            if val[i] > 0:
                index_replace = i
                break
        # find smallest positive
        for i in range(len(ans), 0, -1):
            if ans[i-1] > 0:
                index_replaced_a = i-1
                break
        # find largest negative
        for i in range(k, len(val)):
            if val[i] < 0:
                index_replace_a = i
                break

        if index_replaced==None or index_replace==None:
            ans[index_replaced_a] = val[index_replace_a]
        elif index_replaced_a==None or index_replace_a==None:
            ans[index_replaced] = val[index_replace]
        elif (ans[index_replaced]/val[index_replace] > 
            ans[index_replaced_a]/val[index_replace_a]):
            ans[index_replaced] = val[index_replace]
        else:
            ans[index_replaced_a] = val[index_replace_a]

    # multiplication
    result = 1
    for i in range(len(ans)):
        result = (result * ans[i]) % MOD

    print(result)

else: # negative case
    ans = val[len(val)-k:]
    result = 1
    for i in range(len(ans)):
        result = (result * ans[i]) % MOD

    print(result)


### FIXED CODE ###

from collections import deque
rand = False
verbose = False

if rand:
    import random
    N, K = 200000, 10000
    A = random.choices(range(-10**9, 10**9), k=N)
else:
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

MOD = 10**9 + 7

def mul(A):
    ret = 1
    for i in range(len(A)):
        ret = (ret * A[i]) % MOD
#        print (ret)
    return ret

if K==N:
    print(mul(A))
    exit()

POS, NEG = list(), list()
for i in range(len(A)):
    if A[i] < 0:
        NEG.append(A[i])
    else:
        POS.append(A[i])

POS.sort(reverse=True)
NEG.sort()

if len(POS)==0 and K%2==1: # must go negative
    print(mul(NEG[-K:]))
    exit()

POS = deque(POS)
NEG = deque(NEG)

ans = list()
while len(ans)<K:
    if len(NEG) <= 1:
        if verbose: print('no more neg numbers')
        ans.append(POS.popleft()) # no negative numbers to add
    elif len(POS) <= 1:
        if verbose: print('no more pos numbers')
        if K-len(ans)>=2:
            ans.append(NEG.popleft())
            ans.append(NEG.popleft())
        else:
            ans.append(POS.popleft())
    elif POS[0]*POS[1] > NEG[0]*NEG[1] or K-len(ans)==1:
        if verbose: print('pos bigger')
        ans.append(POS.popleft())
    else:
        if verbose: print('neg biger')
        ans.append(NEG.popleft())
        ans.append(NEG.popleft())

print(mul(ans))