import sys



sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

p2D = lambda x: print(*x, sep="\n")

def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return sys.stdin.readline()[:-1]



def cal(xx):

    res=1

    for x in xx:

        res=res*x%md

    return res



md=10**9+7

n,k=MI()

aa=LI()

if n==k:

    print(cal(aa))

    exit()

aa.sort(key=lambda x:-abs(x))

#print(aa)

pre=aa[:k]

pos=aa[k:]

mnp=mnn=md

mnpi=mnni=-1

neg=0

for i,a in enumerate(pre):

    if a==0:

        print(0)

        exit()

    if a<0:neg+=1

    if a>0 and a<mnp:

        mnp=a

        mnpi=i

    if a<0 and -a<mnn:

        mnn=-a

        mnni=i

if neg%2:

    mxp=mxn=0

    for a in pos:

        if a > 0 and a > mxp:

            mxp = a

        if a < 0 and -a > mxn:

            mxn = -a

    if (mnni!=-1 and mxp) or (mnpi!=-1 and mxn):

        if mnpi==-1 or mxp*mnp>mxn*mnn:pre[mnni]=mxp

        else:pre[mnpi]=-mxn

    else:

        pre=aa[-k:]



print(cal(pre))

import sys



sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

p2D = lambda x: print(*x, sep="\n")

def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return sys.stdin.readline()[:-1]



def main():

    pos = []

    neg = []

    for a in aa:

        if a < 0: neg.append(a)

        else: pos.append(a)

    pn = len(pos)

    nn = len(neg)

    if min(k,nn) // 2 * 2 + pn < k:

        aa.sort(key=lambda x: abs(x))

        print(cal(aa[:k]))

    else:

        pos.sort()

        neg.sort(reverse=True)

        ans = pos.pop() if k & 1 else 1

        mul = []

        while len(pos) > 1: mul.append(pos.pop() * pos.pop())

        while len(neg) > 1: mul.append(neg.pop() * neg.pop())

        mul.sort(reverse=True)

        print(ans * cal(mul[:k // 2]) % md)



def cal(xx):

    res=1

    for x in xx:

        res=res*x%md

    return res



md=10**9+7

n,k=MI()

aa=LI()

main()

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def SI():
    return sys.stdin.readline()[:-1]


def cal(xx):
    res = 1
    for x in xx:
        res = res * x % md
    return res


md = 10**9 + 7
n, k = MI()
aa = LI()
if n == k:
    print(cal(aa))
    exit()
aa.sort(key=lambda x: -abs(x))
# print(aa)
pre = aa[:k]
pos = aa[k:]
mnp = mnn = md
mnpi = mnni = -1
neg = 0
for i, a in enumerate(pre):
    if a == 0:
        print(0)
        exit()
    if a < 0:
        neg += 1
    if a > 0 and a < mnp:
        mnp = a
        mnpi = i
    if a < 0 and -a < mnn:
        mnn = -a
        mnni = i
if neg % 2:
    mxp = mxn = 0
    for a in pos:
        if a > 0 and a > mxp:
            mxp = a
        if a < 0 and -a > mxn:
            mxn = -a
    if (mnni != -1 and mxp) or (mnpi != -1 and mxn):
        if mnpi == -1 or mxp * mnp > mxn * mnn:
            pre[mnni] = mxp
        else:
            pre[mnpi] = -mxn
    else:
        pre = aa[-k:]
print(cal(pre))

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def SI():
    return sys.stdin.readline()[:-1]


def main():
    pos = []
    neg = []
    for a in aa:
        if a < 0:
            neg.append(a)
        else:
            pos.append(a)
    pn = len(pos)
    nn = len(neg)
    if min(k, nn) // 2 * 2 + pn < k:
        aa.sort(key=lambda x: abs(x))
        print(cal(aa[:k]))
    else:
        pos.sort()
        neg.sort(reverse=True)
        ans = pos.pop() if k & 1 else 1
        mul = []
        while len(pos) > 1:
            mul.append(pos.pop() * pos.pop())
        while len(neg) > 1:
            mul.append(neg.pop() * neg.pop())
        mul.sort(reverse=True)
        print(ans * cal(mul[: k // 2]) % md)


def cal(xx):
    res = 1
    for x in xx:
        res = res * x % md
    return res


md = 10**9 + 7
n, k = MI()
aa = LI()
main()

+def main(): +    pos = [] +    neg = [] +    for a in aa: +        if a < 0: +            neg.append(a) +        else: +            pos.append(a) +    pn = len(pos) +    nn = len(neg) +    if min(k, nn) // 2 * 2 + pn < k: +        aa.sort(key=lambda x: abs(x)) +        print(cal(aa[:k])) +    else: +        pos.sort() +        neg.sort(reverse=True) +        ans = pos.pop() if k & 1 else 1 +        mul = [] +        while len(pos) > 1: +            mul.append(pos.pop() * pos.pop()) +        while len(neg) > 1: +            mul.append(neg.pop() * neg.pop()) +        mul.sort(reverse=True) +        print(ans * cal(mul[: k // 2]) % md) + + -if n == k: -    print(cal(aa)) -    exit() -aa.sort(key=lambda x: -abs(x)) -# print(aa) -pre = aa[:k] -pos = aa[k:] -mnp = mnn = md -mnpi = mnni = -1 -neg = 0 -for i, a in enumerate(pre): -    if a == 0: -        print(0) -        exit() -    if a < 0: -        neg += 1 -    if a > 0 and a < mnp: -        mnp = a -        mnpi = i -    if a < 0 and -a < mnn: -        mnn = -a -        mnni = i -if neg % 2: -    mxp = mxn = 0 -    for a in pos: -        if a > 0 and a > mxp: -            mxp = a -        if a < 0 and -a > mxn: -            mxn = -a -    if (mnni != -1 and mxp) or (mnpi != -1 and mxn): -        if mnpi == -1 or mxp * mnp > mxn * mnn: -            pre[mnni] = mxp -        else: -            pre[mnpi] = -mxn -    else: -        pre = aa[-k:] -print(cal(pre)) +main()