import itertools
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq

MOD = 10 ** 9 + 7


def solve(N, K, As):
    originalK = K
    # print(N, ",", K, ",", As)
    minus = [a for a in As if a < 0]
    minus.sort(reverse=True)
    zero = [a for a in As if a == 0]
    plus = [a for a in As if a > 0]
    plus.sort()

    if len(zero) and len(zero) > N - K:
        return 0

    ans = 1
    while K >= 2 and (len(plus) >= 2 or len(minus) >= 2):
        p1 = -1
        p2 = -1
        m = -1
        if len(plus) >= 1:
            p1 = plus[-1]
        if len(plus) >= 2:
            p2 = plus[-1] * plus[-2]
        if len(minus) >= 2:
            m = minus[-1] * minus[-2]

        if m >= p2:
            ans *= (m % MOD)
            ans %= MOD
            minus.pop()
            minus.pop()
            K -= 2
        else:
            ans *= (p1 % MOD)
            ans %= MOD
            plus.pop()
            K -= 1

    while K > 0:
        if len(plus):
            ans *= plus.pop()
            ans %= MOD
        else:
            ans *= minus.pop(0)
        K -= 1
    if ans < 0 and zero:
        return 0
    if ans < 0:
        minus = [a for a in As if a < 0]
        plus = [a for a in As if a > 0]
        minus.sort()
        plus.sort(reverse=True)
        ans = 1
        for _ in range(originalK):
            if plus and minus:
                if abs(plus[-1]) < abs(minus[-1]):
                    ans *= plus.pop()
                else:
                    ans *= minus.pop()
            elif plus:
                ans *= plus.pop()
            else:
                ans *= minus.pop()
            ans %= MOD
        ans %= MOD

    return ans


def slowsolve(N, K, As):
    ans = -10 ** 9
    for p in itertools.combinations(As, K):
        k = 1
        for i in p:
            k *= i
        ans = max(ans, k)
    return ans


# #
# assert (solve(1, 1, [0]) == 0)
# assert (solve(3, 2, [0, 1, 0]) == 0)
# assert (solve(3, 2, [0, 1, 0]) == 0)
# assert (solve(5, 2, [1, 2, -1, -3, -4]) == 12)
# assert (solve(1, 1, [-4]) == -4 % MOD)
# assert (solve(2, 1, [-4, 0]) == 0)
# assert (solve(2, 1, [-1, -4]) == -1  % MOD)
# assert (solve(10, 5, [-2, 1, -3, 2, 0, -1, 3, -2, -2, -3]) == 108)
# assert (solve(10, 5, [-1, 2, 2, 0, 2, -2, -1, 0, -3, -1]) == 48)
# assert (solve(10, 5, [0, 0, -3, 3, 3, 2, 2, 0, 3, -1]) == 108)
# assert (solve(10, 5, [-1, -2, -1, -3, -2, -3, -2, -3, -1, -2]) == -4 % MOD)

# (solve(5 , 5 , [-3, -5, -5, -4, -4] == (-3 * -5 * -5 * -4 * -4) % MOD))

#
# print(slowsolve(10 , 5 , [0, 0, -3, 3, 3, 2, 2, 0, 3, -1]))
# print(solve(10 , 5 , [0, 0, -3, 3, 3, 2, 2, 0, 3, -1]))
#
# exit()


def rand(N, a, b):
    import random
    return [random.randint(a, b) for _ in range(N)]


#
#
# for _ in range(100000):
#     N = 6
#     A = 1
#     B = 10
#     K = 3
#     As = rand(N, A, B)
#     slow = slowsolve(N, K, As)
#     ans = solve(N, K, As)
#     slow %= MOD
#     if slow != ans:
#         print(N, ",", K, ",", As)
#         print(slow)
#         print(ans)
#         assert (slow == ans)
#
# print("OK")

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, K, As))


Measured memory_bytes: 33436