# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



n,k,*a = list(map(int,read().split()))



pos = []

neg = []

#both = []

zero = 0



for i in a:

    #if i!=0: both.append(i)

    

    if i==0: zero += 1

    elif i > 0: pos.append(i)

    else: neg.append(-i)



#print(pos,neg,zero)

MOD = 10**9+7



if n - zero < k: # ゼロが多すぎる

    print((0))

elif pos == []: # 全部ゼロ以下

    if k%2==0:

        neg.sort(reverse=True)

        ans = 1

        for i in range(k):

            ans *= neg[i]

            ans %= MOD

        print(ans)

    else:

        if zero:

            print((0))

        else: # 負のみ

            neg.sort()

            ans = -1

            for i in range(k):

                ans *= neg[i]

                ans %= MOD

            print((ans%MOD))

            

else: #正もいる

    pos.sort(reverse=True)

    neg.sort(reverse=True)

    cp = len(pos)

    cn = len(neg)

    

    i = j = 0    

    for _ in range(k):

        if i == cp:

            j += 1

        elif j == cn:

            i += 1

        else:

            if pos[i] > neg[j]:

                i += 1

            else:

                j += 1

    

    #print(cp,cn,i,j)

    if j%2 == 0:

        ans = 1

        for x in pos[:i]:

            ans *= x

            ans %= MOD

        for x in neg[:j]:

            ans *= x

            ans %= MOD

        print(ans)

            

    else:

        can_i = i and j < cn

        can_j = j and i < cp

        if not can_i and not can_j:

            if zero: print((0))

            else:

                ans = -1

                for x in pos[:i]:

                    ans *= x

                    ans %= MOD

                for x in neg[:j]:

                    ans *= x

                    ans %= MOD

                print(ans)

            exit()

                

                

        if not can_i:

            j -= 1

            i += 1

        elif not can_j:

            j += 1

            i -= 1

        else:

            if pos[i]*pos[i-1] >= neg[j]*neg[j-1]:

                j -= 1

                i += 1

            else:

                j += 1

                i -= 1



        ans = 1                

        for x in pos[:i]:

            ans *= x

            ans %= MOD

        for x in neg[:j]:

            ans *= x

            ans %= MOD

        print(ans)

            

            

            









# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



n,k,*a = list(map(int,read().split()))



pos = []

neg = []

MOD = 10**9+7



for i in a:

    if i >= 0: pos.append(i)

    else: neg.append(i)



if n==k:

    ans = 1

    for i in a:

        ans *= i

        ans %= MOD

    print(ans)



elif pos == []: # 全部負

    if k%2==0:

        neg.sort()

        ans = 1

        for i in range(k):

            ans *= neg[i]

            ans %= MOD

        print(ans)

    else:

        neg.sort(reverse=True)

        ans = 1

        for i in range(k):

            ans *= neg[i]

            ans %= MOD

        print((ans%MOD))

            

else: #正もいる

    pos.sort()

    neg.sort(reverse=True)

    if k&1:

        ans = pos.pop()%MOD

    else:

        ans = 1

    

    res = []

    while len(pos)>1:

        x,y=pos.pop(),pos.pop()

        res.append(x*y)

    while len(neg)>1:

        x,y=neg.pop(),neg.pop()

        res.append(x*y)



    res.sort(reverse=True)

    for i in range(k//2):

        ans *= res[i]

        ans %= MOD

    print(ans)



    
# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
n, k, *a = list(map(int, read().split()))
pos = []
neg = []
# both = []
zero = 0
for i in a:
    # if i!=0: both.append(i)
    if i == 0:
        zero += 1
    elif i > 0:
        pos.append(i)
    else:
        neg.append(-i)
# print(pos,neg,zero)
MOD = 10**9 + 7
if n - zero < k:  # ゼロが多すぎる
    print((0))
elif pos == []:  # 全部ゼロ以下
    if k % 2 == 0:
        neg.sort(reverse=True)
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print(ans)
    else:
        if zero:
            print((0))
        else:  # 負のみ
            neg.sort()
            ans = -1
            for i in range(k):
                ans *= neg[i]
                ans %= MOD
            print((ans % MOD))
else:  # 正もいる
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    cp = len(pos)
    cn = len(neg)
    i = j = 0
    for _ in range(k):
        if i == cp:
            j += 1
        elif j == cn:
            i += 1
        else:
            if pos[i] > neg[j]:
                i += 1
            else:
                j += 1
    # print(cp,cn,i,j)
    if j % 2 == 0:
        ans = 1
        for x in pos[:i]:
            ans *= x
            ans %= MOD
        for x in neg[:j]:
            ans *= x
            ans %= MOD
        print(ans)
    else:
        can_i = i and j < cn
        can_j = j and i < cp
        if not can_i and not can_j:
            if zero:
                print((0))
            else:
                ans = -1
                for x in pos[:i]:
                    ans *= x
                    ans %= MOD
                for x in neg[:j]:
                    ans *= x
                    ans %= MOD
                print(ans)
            exit()
        if not can_i:
            j -= 1
            i += 1
        elif not can_j:
            j += 1
            i -= 1
        else:
            if pos[i] * pos[i - 1] >= neg[j] * neg[j - 1]:
                j -= 1
                i += 1
            else:
                j += 1
                i -= 1
        ans = 1
        for x in pos[:i]:
            ans *= x
            ans %= MOD
        for x in neg[:j]:
            ans *= x
            ans %= MOD
        print(ans)

# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
n, k, *a = list(map(int, read().split()))
pos = []
neg = []
MOD = 10**9 + 7
for i in a:
    if i >= 0:
        pos.append(i)
    else:
        neg.append(i)
if n == k:
    ans = 1
    for i in a:
        ans *= i
        ans %= MOD
    print(ans)
elif pos == []:  # 全部負
    if k % 2 == 0:
        neg.sort()
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print(ans)
    else:
        neg.sort(reverse=True)
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print((ans % MOD))
else:  # 正もいる
    pos.sort()
    neg.sort(reverse=True)
    if k & 1:
        ans = pos.pop() % MOD
    else:
        ans = 1
    res = []
    while len(pos) > 1:
        x, y = pos.pop(), pos.pop()
        res.append(x * y)
    while len(neg) > 1:
        x, y = neg.pop(), neg.pop()
        res.append(x * y)
    res.sort(reverse=True)
    for i in range(k // 2):
        ans *= res[i]
        ans %= MOD
    print(ans)

-# both = [] -zero = 0 +MOD = 10**9 + 7 -    # if i!=0: both.append(i) -    if i == 0: -        zero += 1 -    elif i > 0: +    if i >= 0: -        neg.append(-i) -# print(pos,neg,zero) -MOD = 10**9 + 7 -if n - zero < k:  # ゼロが多すぎる -    print((0)) -elif pos == []:  # 全部ゼロ以下 +        neg.append(i) +if n == k: +    ans = 1 +    for i in a: +        ans *= i +        ans %= MOD +    print(ans) +elif pos == []:  # 全部負 -        neg.sort(reverse=True) +        neg.sort() -        if zero: -            print((0)) -        else:  # 負のみ -            neg.sort() -            ans = -1 -            for i in range(k): -                ans *= neg[i] -                ans %= MOD -            print((ans % MOD)) +        neg.sort(reverse=True) +        ans = 1 +        for i in range(k): +            ans *= neg[i] +            ans %= MOD +        print((ans % MOD)) -    pos.sort(reverse=True) +    pos.sort() -    cp = len(pos) -    cn = len(neg) -    i = j = 0 -    for _ in range(k): -        if i == cp: -            j += 1 -        elif j == cn: -            i += 1 -        else: -            if pos[i] > neg[j]: -                i += 1 -            else: -                j += 1 -    # print(cp,cn,i,j) -    if j % 2 == 0: +    if k & 1: +        ans = pos.pop() % MOD +    else: -        for x in pos[:i]: -            ans *= x -            ans %= MOD -        for x in neg[:j]: -            ans *= x -            ans %= MOD -        print(ans) -    else: -        can_i = i and j < cn -        can_j = j and i < cp -        if not can_i and not can_j: -            if zero: -                print((0)) -            else: -                ans = -1 -                for x in pos[:i]: -                    ans *= x -                    ans %= MOD -                for x in neg[:j]: -                    ans *= x -                    ans %= MOD -                print(ans) -            exit() -        if not can_i: -            j -= 1 -            i += 1 -        elif not can_j: -            j += 1 -            i -= 1 -        else: -            if pos[i] * pos[i - 1] >= neg[j] * neg[j - 1]: -                j -= 1 -                i += 1 -            else: -                j += 1 -                i -= 1 -        ans = 1 -        for x in pos[:i]: -            ans *= x -            ans %= MOD -        for x in neg[:j]: -            ans *= x -            ans %= MOD -        print(ans) +    res = [] +    while len(pos) > 1: +        x, y = pos.pop(), pos.pop() +        res.append(x * y) +    while len(neg) > 1: +        x, y = neg.pop(), neg.pop() +        res.append(x * y) +    res.sort(reverse=True) +    for i in range(k // 2): +        ans *= res[i] +        ans %= MOD +    print(ans)