#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld E = 1e-18;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, T, pr1[200005], pr2[200005], sf1[200005], sf2[200005];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h;
        h *= h;
        //h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

struct segment_tree_1
{
    pii d[2000001];
    bool tt[2000001];
    bool leaf[2000001];
    int sz;

    void build(int h,int l,int r)
    {
        if (l==r)
        {
            d[h]=mp(0,0);
            leaf[h]=1;
        }
    }

    void build(int h)
    {
        sz=h;
        build(1,0,sz);
    }

    void update(int h,int l,int r,int x,int k)
    {
        push(h);
        if (l==r)
        {
            d[h].fi+=k;
            d[h].se+=k;
            return;
        }
        int w=(l+r)/2;
        if (x<=w) update(h*2,l,w,x,k); else update(h*2+1,w+1,r,x,k);
        d[h].fi=max(d[h*2].fi,d[h*2+1].fi);
        d[h].se=min(d[h*2].se,d[h*2+1].se);
    }

    void update(int x,int k)
    {
        update(1,0,sz,x,k);
    }

    inline void push(int h)
    {
        if (tt[h])
        {
            if (!leaf[h])
            {
                tt[h*2]^=tt[h];
                swap(d[h*2].fi,d[h*2].se);
                tt[h*2+1]^=tt[h];
                swap(d[h*2+1].fi,d[h*2+1].se);
            }
            tt[h]=0;
        }
    }

    void rev(int h,int l,int r,int x,int y)
    {
        if (x>y) return;
        if (l==x && y==r)
        {
            swap(d[h].fi,d[h].se);
            tt[h]=1;
            return;
        }
        int w=(l+r)/2;
        rev(h*2,l,w,x,min(y,w));
        rev(h*2+1,w+1,r,max(x,w+1),y);
        d[h].fi=max(d[h*2].fi,d[h*2+1].fi);
        d[h].se=max(d[h*2].se,d[h*2+1].se);
    }

    void rev(int x,int y)
    {
        rev(1,0,sz,x,y);
    }
};

//segment_tree_1 g;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll k;
    cin >> n >> k;
    bool tt=0;
    vector<ll> v1, v2;
    for (int i = 1; i <= n; i++)
    {
        ll x;
        cin >> x;
        if (x<0) v2.pb(abs(x));
        if (x==0) tt=1;
        if (x>0) v1.pb(x);
    }
    sort(all(v1));
    if (v1.size())
    {
        sf1[v1.size()]=1;
        for (int i = v1.size()-1; i > -1; i--)
        {
            sf1[i]=(sf1[i+1]*v1[i])%MOD;
        }
        pr1[0]=v1[0];
        for (int i = 1; i < v1.size(); i++)
        {
            pr1[i]=(pr1[i-1]*v1[i])%MOD;
        }
    }
    sort(all(v2));
    reverse(all(v2));
    if (v2.size())
    {
        sf2[v2.size()]=1;
        for (int i = v2.size()-1; i > -1; i--)
        {
            sf2[i]=(sf2[i+1]*v2[i])%MOD;
        }
        pr2[0]=v2[0];
        for (int i = 1; i < v2.size(); i++)
        {
            pr2[i]=(pr2[i-1]*v2[i])%MOD;
        }
        //sort(all(v2));
    }
    if (v1.size()+v2.size()<k) {cout << "0\n";exit(0);}
    if (v1.size()==0)
    {
        //cout << "----\n";
        if (v2.size()<k) {cout << "0\n";exit(0);}
        if (k%2)
        {
            if (tt) {cout << "0\n";return 0;}
            //cout << sf2[v2.size()-k] << "\n";
            cout << (MOD-sf2[v2.size()-k])%MOD << "\n";
            exit(0);
        }else
        {
            cout << pr2[k-1] << "\n";
            exit(0);
        }
    }
    if (v2.size()==0)
    {
        if (v1.size()<k) {cout << "0\n";exit(0);}
        cout << sf1[v1.size()-k] << "\n";
        exit(0);
    }
    bool t1=0;
    ll l=-1, r=v1.size(), ans=1;
    if (k%2)
    {
        ans=ans*v1[r-1]%MOD;
        r--;
    }
    //cout << "----\n";
    //cout << v2.size() << "\n";
    //for (int i = 0; i < v2.size(); i++) cout << v2[i] << " ";
    //cout << "\n";
    for (int i = 1; i <= k/2; i++)
    {
        ll p1=0, p2=0;
        if (l+2<v2.size()) p2=v2[l+2]*v2[l+1];
        if (r-2>-1) p1=v1[r-1]*v1[r-2];
        if (p1==0 && p2==0) {t1=1;break;}
        if (p1>p2) ans=(ans*(p1%MOD))%MOD, r-=2; else ans=(ans*(p2%MOD))%MOD, l+=2;
    }
    if (!t1)
    {
        cout << ans << "\n";
        exit(0);
    }
    if (tt) {cout << "0\n";exit(0);}
    ans=v2.back()%MOD;
    r=v2.size()-1;l=-1;
    for (int i = 1; i <= k-1; i++)
    {
        ll p1=1e18, p2=1e18;
        if (r-1>-1) p2=v2[r-1];
        if (l+1<v1.size()) p1=v1[l+1];
        if (p1<p2) ans=(ans*p1)%MOD, l++; else ans=(ans*p2)%MOD, r--;
    }
    cout << (MOD-ans)%MOD;
    return 0;
}

/*
3
4 2
1 1
1 0
3 2
2 2

3 1
1 1
1 0
3 2

3 2
1 1
1 0
3 2
*/


Measured memory_bytes: 8552