from functools import reduce
from collections import deque
#import operator

#解説見た

def solve(N, K, A):
    MOD = int(1e9 + 7)
    A_plus = [x for x in A if x >= 0]
    A_plus.sort(reverse=True)
    A_minus = [x for x in A if x < 0]
    A_minus.sort()
    #print('+', len(A_plus))
    #print('-',len(A_minus))
    #from collections import Counter
    #print(Counter(A_plus))
    #print(Counter(A_minus))

    if K == 1:
        return max(A) % MOD
    if K == N:
        #ans = reduce(operator.mul, A)
        ans = 1
        for t in A:
            ans *= t
            ans %= MOD
        return ans % MOD

    if len(A_plus) == 0:
        #minusだけから選ぶ場合
        if K % 2 == 1:
            #答えは負になるので、絶対値が小さい順に積を取る
            ans = 1
            for t in list(reversed(A_minus))[:K]:
                ans *= t
                ans %= MOD
            return ans
        else:
            #答えは正になるので、絶対値が大きい順に積をとる
            ans = 1
            for t in A_minus[:K]:
                ans *= t
                ans %= MOD
            return ans
    
    k = K
    S = []
    A_plus = deque(A_plus)
    A_minus = deque(A_minus)
    if k % 2 == 1:
        t = A_plus.popleft()
        S.append(t)
        k -= 1
    #kは偶数になった
    assert k % 2 == 0
    while k > 0:
        if len(A_minus) < 2:
            #print('k',k)
            #print('+', list(A_plus))
            #print('-',list(A_minus))
            t1 = A_plus.popleft()
            S.append(t1)
            t2 = A_plus.popleft()
            S.append(t2)
            k -= 2
        elif len(A_plus) < 2:
            t1 = A_minus.popleft()
            S.append(t1)
            t2 = A_minus.popleft()
            S.append(t2)
            k -= 2
        else:
            t_p = A_plus[0] * A_plus[1]
            t_m = A_minus[0] * A_minus[1]
            if t_p >= t_m:
                t1 = A_plus.popleft()
                S.append(t1)
                t2 = A_plus.popleft()
                S.append(t2)
                assert t1 * t2 == t_p
                k -= 2
            else:
                t1 = A_minus.popleft()
                S.append(t1)
                t2 = A_minus.popleft()
                S.append(t2)
                assert t1 * t2 == t_m
                k -= 2
    #print(Counter(S))
    #print(len(S), K)
    ans = 1
    for t in S:
        ans *= t
        ans %= MOD
    return ans % MOD

if __name__ == "__main__":
    with open('ABC173E/random_mz03.txt', 'r') as f:
        input = f.readline
        N, K = tuple(int(c) for c in input().split())
        A = [int(c) for c in input().split()]
        ret = solve(N, K, A)
        print(ret)

### FIXED CODE ###

from functools import reduce
from collections import deque
#import operator

#解説見た

def solve(N, K, A):
    MOD = int(1e9 + 7)
    A_plus = [x for x in A if x >= 0]
    A_plus.sort(reverse=True)
    A_minus = [x for x in A if x < 0]
    A_minus.sort()
    #print('+', len(A_plus))
    #print('-',len(A_minus))
    #from collections import Counter
    #print(Counter(A_plus))
    #print(Counter(A_minus))

    if K == 1:
        return max(A) % MOD
    if K == N:
        #ans = reduce(operator.mul, A)
        ans = 1
        for t in A:
            ans *= t
            ans %= MOD
        return ans % MOD

    if len(A_plus) == 0:
        #minusだけから選ぶ場合
        if K % 2 == 1:
            #答えは負になるので、絶対値が小さい順に積を取る
            ans = 1
            for t in list(reversed(A_minus))[:K]:
                ans *= t
                ans %= MOD
            return ans
        else:
            #答えは正になるので、絶対値が大きい順に積をとる
            ans = 1
            for t in A_minus[:K]:
                ans *= t
                ans %= MOD
            return ans
    
    k = K
    S = []
    A_plus = deque(A_plus)
    A_minus = deque(A_minus)
    if k % 2 == 1:
        t = A_plus.popleft()
        S.append(t)
        k -= 1
    #kは偶数になった
    assert k % 2 == 0
    while k > 0:
        if len(A_minus) < 2:
            #print('k',k)
            #print('+', list(A_plus))
            #print('-',list(A_minus))
            t1 = A_plus.popleft()
            S.append(t1)
            t2 = A_plus.popleft()
            S.append(t2)
            k -= 2
        elif len(A_plus) < 2:
            t1 = A_minus.popleft()
            S.append(t1)
            t2 = A_minus.popleft()
            S.append(t2)
            k -= 2
        else:
            t_p = A_plus[0] * A_plus[1]
            t_m = A_minus[0] * A_minus[1]
            if t_p >= t_m:
                t1 = A_plus.popleft()
                S.append(t1)
                t2 = A_plus.popleft()
                S.append(t2)
                assert t1 * t2 == t_p
                k -= 2
            else:
                t1 = A_minus.popleft()
                S.append(t1)
                t2 = A_minus.popleft()
                S.append(t2)
                assert t1 * t2 == t_m
                k -= 2
    #print(Counter(S))
    #print(len(S), K)
    ans = 1
    for t in S:
        ans *= t
        ans %= MOD
    return ans % MOD

if __name__ == "__main__":
    #with open('ABC173E/random_mz03.txt', 'r') as f:
    #    input = f.readline
    N, K = tuple(int(c) for c in input().split())
    A = [int(c) for c in input().split()]
    ret = solve(N, K, A)
    print(ret)