def solve():

    P.sort(reverse = True)

    M.sort()

    P.append(-1)

    M.append(1) # add endpoint

    p, m = [], []

    while len(p) + len(m) < k:

        if P[len(p)] < -M[len(m)]:

            m.append(M[len(m)])

        else:

            p.append(P[len(p)])

    if len(m)%2 == 0: return p + m



    exist_p = len(p) > 0

    exist_m = len(m) > 0

    remain_P = len(P) - 1 > len(p)

    remain_M = len(M) - 1 > len(m)

    if exist_p & remain_M & exist_m & remain_P:

        if abs(p[-1] * P[len(p)]) < abs(m[-1] * M[len(m)]):

            p.pop()

            m.append(M[len(m)])

        else:

            m.pop()

            p.append(P[len(p)])

    elif exist_p & remain_M:

        p.pop()

        m.append(M[len(m)])

    elif exist_m & remain_P:

        m.pop()

        p.append(P[len(p)])

    else:

        M.pop() # del endpoint

        m = sorted(M, reverse = True)[:k]

    return p + m



n, k = list(map(int, input().split()))

P, M = [], [] # plus, minus

for a in map(int, input().split()):

    if a < 0: M.append(a)

    else: P.append(a)

ans, MOD = 1, 10**9 + 7

for a in solve(): ans *= a; ans %= MOD

ans += MOD; ans %= MOD

print(ans)

from logging import *

basicConfig(level=DEBUG, format='%(levelname)s: %(message)s')

disable(CRITICAL)



def solve():

    P.sort(reverse = True)

    M.sort()

    debug('k {} n {}'.format(k,n))

    debug('P {}'.format(P))

    debug('M {}'.format(M))

    can_positive = False

    if len(P) > 0:

        if k < n: can_positive = True

        else: can_positive = len(M)%2 == 0

    else: can_positive = k%2 == 0



    if can_positive:

        debug('positive')

        P.sort()

        M.sort(reverse = True)

        p0 = []

        if k%2: p0.append(P.pop())

        ar = []

        while len(P) >= 2: ar.append(P.pop() * P.pop())

        while len(M) >= 2: ar.append(M.pop() * M.pop())

        ar.sort(reverse = True)

        debug('p0 {}'.format(p0))

        debug('ar {}'.format(ar))

        debug('ar[:k] {}'.format(ar[:(k-k%2)//2]))

        return p0 + ar[:(k-k%2)//2]

    else: # can negative

        debug('negative')

        return sorted(P+M, key=lambda x: abs(x))[:k]





n, k = list(map(int, input().split()))

P, M = [], [] # plus, minus

for a in map(int, input().split()):

    if a < 0: M.append(a)

    else: P.append(a)

ans, MOD = 1, 10**9 + 7

for a in solve(): ans *= a; ans %= MOD

ans += MOD; ans %= MOD

print(ans)

def solve():
    P.sort(reverse=True)
    M.sort()
    P.append(-1)
    M.append(1)  # add endpoint
    p, m = [], []
    while len(p) + len(m) < k:
        if P[len(p)] < -M[len(m)]:
            m.append(M[len(m)])
        else:
            p.append(P[len(p)])
    if len(m) % 2 == 0:
        return p + m
    exist_p = len(p) > 0
    exist_m = len(m) > 0
    remain_P = len(P) - 1 > len(p)
    remain_M = len(M) - 1 > len(m)
    if exist_p & remain_M & exist_m & remain_P:
        if abs(p[-1] * P[len(p)]) < abs(m[-1] * M[len(m)]):
            p.pop()
            m.append(M[len(m)])
        else:
            m.pop()
            p.append(P[len(p)])
    elif exist_p & remain_M:
        p.pop()
        m.append(M[len(m)])
    elif exist_m & remain_P:
        m.pop()
        p.append(P[len(p)])
    else:
        M.pop()  # del endpoint
        m = sorted(M, reverse=True)[:k]
    return p + m


n, k = list(map(int, input().split()))
P, M = [], []  # plus, minus
for a in map(int, input().split()):
    if a < 0:
        M.append(a)
    else:
        P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve():
    ans *= a
    ans %= MOD
ans += MOD
ans %= MOD
print(ans)

from logging import *

basicConfig(level=DEBUG, format="%(levelname)s: %(message)s")
disable(CRITICAL)


def solve():
    P.sort(reverse=True)
    M.sort()
    debug("k {} n {}".format(k, n))
    debug("P {}".format(P))
    debug("M {}".format(M))
    can_positive = False
    if len(P) > 0:
        if k < n:
            can_positive = True
        else:
            can_positive = len(M) % 2 == 0
    else:
        can_positive = k % 2 == 0
    if can_positive:
        debug("positive")
        P.sort()
        M.sort(reverse=True)
        p0 = []
        if k % 2:
            p0.append(P.pop())
        ar = []
        while len(P) >= 2:
            ar.append(P.pop() * P.pop())
        while len(M) >= 2:
            ar.append(M.pop() * M.pop())
        ar.sort(reverse=True)
        debug("p0 {}".format(p0))
        debug("ar {}".format(ar))
        debug("ar[:k] {}".format(ar[: (k - k % 2) // 2]))
        return p0 + ar[: (k - k % 2) // 2]
    else:  # can negative
        debug("negative")
        return sorted(P + M, key=lambda x: abs(x))[:k]


n, k = list(map(int, input().split()))
P, M = [], []  # plus, minus
for a in map(int, input().split()):
    if a < 0:
        M.append(a)
    else:
        P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve():
    ans *= a
    ans %= MOD
ans += MOD
ans %= MOD
print(ans)

+from logging import * + +basicConfig(level=DEBUG, format="%(levelname)s: %(message)s") +disable(CRITICAL) + + -    P.append(-1) -    M.append(1)  # add endpoint -    p, m = [], [] -    while len(p) + len(m) < k: -        if P[len(p)] < -M[len(m)]: -            m.append(M[len(m)]) +    debug("k {} n {}".format(k, n)) +    debug("P {}".format(P)) +    debug("M {}".format(M)) +    can_positive = False +    if len(P) > 0: +        if k < n: +            can_positive = True -            p.append(P[len(p)]) -    if len(m) % 2 == 0: -        return p + m -    exist_p = len(p) > 0 -    exist_m = len(m) > 0 -    remain_P = len(P) - 1 > len(p) -    remain_M = len(M) - 1 > len(m) -    if exist_p & remain_M & exist_m & remain_P: -        if abs(p[-1] * P[len(p)]) < abs(m[-1] * M[len(m)]): -            p.pop() -            m.append(M[len(m)]) -        else: -            m.pop() -            p.append(P[len(p)]) -    elif exist_p & remain_M: -        p.pop() -        m.append(M[len(m)]) -    elif exist_m & remain_P: -        m.pop() -        p.append(P[len(p)]) +            can_positive = len(M) % 2 == 0 -        M.pop()  # del endpoint -        m = sorted(M, reverse=True)[:k] -    return p + m +        can_positive = k % 2 == 0 +    if can_positive: +        debug("positive") +        P.sort() +        M.sort(reverse=True) +        p0 = [] +        if k % 2: +            p0.append(P.pop()) +        ar = [] +        while len(P) >= 2: +            ar.append(P.pop() * P.pop()) +        while len(M) >= 2: +            ar.append(M.pop() * M.pop()) +        ar.sort(reverse=True) +        debug("p0 {}".format(p0)) +        debug("ar {}".format(ar)) +        debug("ar[:k] {}".format(ar[: (k - k % 2) // 2])) +        return p0 + ar[: (k - k % 2) // 2] +    else:  # can negative +        debug("negative") +        return sorted(P + M, key=lambda x: abs(x))[:k]