#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using LL = long long;
//using LL = __int64;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pLL = pair<LL, LL>;

template< typename T = int > inline T read()
{
    char c = '\0';
    bool f = false;
    T x = 0;
    while(c < '0' || '9' < c) {if(c == '-') f = true; c = getchar();}
    while('0' <= c && c <= '9') {x = (x << 1) + (x << 3) + (c & 0xf); c = getchar();}
    if(f) return -x;
    return x;
}
template< typename T > inline void read(T &x) {x = read<T>();}
template < typename T, typename ...Args > inline void read(T &x, Args &...args) {read(x); read(args...);}

template < typename T > inline void getmin(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void getmax(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define mt make_tuple
#define pb push_back
#define epb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int e5 = 100000; // 1e5
const int e6 = 1000000; //1e6;
const int MOD = 1000000007; //1e9 + 7
//const int MOD = 998244353;
//const int MOD = 911451407;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1;
    for(; n; n >>= 1, a = a * a % mod)
        if(n & 1)
            res = res * a % mod;
    return res;
}

struct Mint
{
    int x;
    Mint():x(0) {}
    Mint(int _x): x(_x)
    {
        if(x < 0 || x >= MOD) x %= MOD;
        if(x < 0) x += MOD;
    }
    Mint(LL _x)
    {
        if(_x < 0 || _x >= MOD) _x %= MOD;
        if(_x < 0) _x += MOD;
        x = _x;
    }
    Mint operator - () const {return Mint(MOD - x);}
    Mint operator + (const Mint &rhs) const {return Mint(x + rhs.x >= MOD ? x + rhs.x - MOD : x + rhs.x);}
    Mint operator - (const Mint &rhs) const {return Mint(x - rhs.x < 0 ? x - rhs.x + MOD : x - rhs.x);}
    Mint operator * (const Mint &rhs) const {return Mint((LL)x * rhs.x % MOD);}
    Mint operator / (const Mint &rhs) const {return Mint((LL)x * fp(rhs.x, -1) % MOD);}
    bool operator == (const Mint &rhs) const {return x == rhs.x;}
    bool operator != (const Mint &rhs) const {return x != rhs.x;}
    Mint& operator += (const Mint &rhs) {x += rhs.x; if(x >= MOD) x -= MOD; return *this;}
    Mint& operator -= (const Mint &rhs) {x -= rhs.x; if(x < 0) x += MOD; return *this;}
    Mint& operator *= (const Mint &rhs) {x = (LL)x * rhs.x % MOD; return *this;}
    Mint& operator /= (const Mint &rhs) {x = (LL)x * fp(rhs.x, -1) % MOD; return *this;}
    friend ostream& operator << (ostream &out, Mint &rhs) {return out << to_string(rhs.x);}
    Mint inv() {return Mint(fp(x, -1));}
    Mint pow(int k) {return Mint(fp(x, k));}
    Mint pow(const Mint &t) {return Mint(fp(x, t.x));}
};


const int maxn = (int) 1e6 + 20;
const int maxm = (int) 2e6 + 20;

void work()
{
    int n, k;
    cin >>n >>k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) read(a[i]);
    sort(rall(a), [](int x, int y) {return abs(x) < abs(y);});

    int f = 0;
    Mint ans = 1;

    for(int i = 0; i < k; i++)
    {
        ans = ans * a[i];
        if(a[i] < 0) f ^= 1;
    }

    if(f)
    {
        LL p0, n0, p1, n1;
        p0 = p1 = n0 = n1 = LINF;

        for(int i = 0; i < k; i++)
        {
            if(a[i] < 0) n0 = a[i];
            if(a[i] >= 0) p0 = a[i];
        }
        for(int i = k; i < n; i++)
        {
            if(n1 == LINF && a[i] < 0) n1 = a[i];
            if(p1 == LINF && a[i] >= 0) p1 = a[i];
        }

        if(p0 != LINF && p1 != LINF && n0 != LINF && n1 != LINF)
        {
            if(p0 * p1 > n0 * n1)
            {
                ans = ans * p1 / n0;
            }
            else
            {
                ans = ans * n1 / p0;
            }
        }
        else if(p0 != LINF && n1 != LINF)
        {
            ans = ans * n1 / p0;
        }
        else if(p1 != LINF && n0 != LINF)
        {
            ans = ans * p1 / n0;
        }
        else
        {
            reverse(all(a));
            ans = 1;
            for(int i = 0; i < k; i++)
                ans *= a[i];
        }
    }

    cout <<ans <<endl;

}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}










Measured memory_bytes: 3664