#include<bits/stdc++.h>
        #define ll long long
        #define f   first
        #define s   second
        #define pb          push_back
        #define mod        1000000007
        #define mod1       1000000009
        #define hell        998244353
        #define inf         1000000000000000000LL
        #define pi          3.14159265358979323
        #define N           1000005
        using namespace std;
        ll n,k,sum,q,res,m,val,ans;
        ll x,y;
        ll xx[]={1,0,-1,0};
        ll yy[]={0,1,0,-1};
        void solve()    
        {   ll a,b;
            cin>>n>>k;
            vector<ll> v(n);
            priority_queue<ll> pq1,pq2;
            for(int i=0;i<n;i++) {cin>>v[i];
                if(v[i]>0) pq1.push(v[i]); 
                else if(v[i]<0)
                pq2.push(-v[i]);}
            ll zeros=n-pq1.size()-pq2.size();
            ll cnt=0;
            if(k>(pq1.size()+pq2.size()))
            {
                cout<<"0";return;
            }
            ll ans=1;
            while(cnt<k)
            {
                if(cnt==k-1)
                {
                    if(pq1.empty())
                    {
                        break;
                    }
                    else
                    {
                        ans=(ans*pq1.top())%mod;
                        cout<<ans;return;
                    }
                }
                if(pq1.size()>=2 and pq2.size()>=2)
                {
                    ll x1=pq1.top();
                    pq1.pop();
                    ll x2=pq1.top();pq1.pop();
                    ll y1=pq2.top();
                    pq2.pop();
                    ll y2=pq2.top();
                    pq2.pop();
                    if(x1*x2<=(y1*y2))
                    {
                        pq1.push(x1);pq1.push(x2);
                        ans=(ans*y1)%mod;
                        ans=(ans*y2)%mod;
                    }
                    else
                    {
                        pq2.push(y1);pq2.push(y2);
                        ans=(ans*x1)%mod;
                        ans=(ans*x2)%mod;
                    }
                    cnt+=2;
                }
                else if(pq1.size()>=2)
                {
                    ll x1=pq1.top();
                    pq1.pop();
                    ll x2=pq1.top();pq1.pop();
                    ans=(ans*x1)%mod;
                    ans=(ans*x2)%mod;
                    cnt+=2;
                }
                else if(pq2.size()>=2)
                {
                    ll y1=pq2.top();
                    pq2.pop();
                    ll y2=pq2.top();
                    pq2.pop();
                    ans=(ans*y1)%mod;
                    ans=(ans*y2)%mod;
                    cnt+=2;
                }
                else break;
            }

            if(cnt==k)
            {
                cout<<ans;return;
            }
            sort(v.begin(),v.end(),greater<ll>());
            ll res=1;
            for(int i=0;i<k;i++)
            {
                res=(res*(mod+v[i])%mod)%mod;
            }
            cout<<res;
            


        }
        int main()
        {   ios_base::sync_with_stdio(false);
            cin.tie(0);cout.tie(0);
            ll t=1;
            //cin>>t;
            while(t--)
                solve();
            

        }            

Measured memory_bytes: 6912