#include<bits/stdc++.h>

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        ll n,k;
        cin>>n>>k;

        ll ar[n];

        vector<pll> g;

        ll allneg=1;

        for(ll i=0;i<n;i++)
        {
            cin>>ar[i];

            if(ar[i]>0)
            {
                g.pb({ar[i],1});
                allneg=0;
            }
            else
            g.pb({-ar[i],-1});
        }

        sort(g.begin(),g.end());

        ll ans=1;

        if(n==k)
        {
            for(ll i=0;i<n;i++)
            {
                ans*=ar[i];
                ans%=MOD;
                ans+=MOD;
                ans%=MOD;
            }

            cout<<ans;
            continue;
        }

        if(allneg==1 && k%2==1) 
        {
            ll cnt=0;
            for(auto i:g)
            {
                ans*=(i.ff*i.ss);
                ans%=MOD;
                ans+=MOD;
                ans%=MOD;
                cnt++;
                if(cnt==k)
                break;
            }
            cout<<ans;
            continue;
        }

        reverse(g.begin(),g.end());

        ll neg=0;

        for(ll i=0;i<k;i++)
        {
            ans*=(g[i].ff*g[i].ss);
            ans%=MOD;
            ans+=MOD;
            ans%=MOD;
            if(g[i].ss==-1)
            neg++;
        }

        if(neg%2==0)
        {
            cout<<ans;
            continue;
        }

        ll mnpos1=0,mnneg1=0,mxpos2=0,mxneg2=0;
        ans=1;

        for(ll i=0;i<k;i++)
        {
            if(g[i].ss==1)
            mnpos1=g[i].ff;
            else
            mnneg1=g[i].ff;
        }

        for(ll i=k;i<n;i++)
        {
            if(g[i].ss==1)
            {
                if(mxpos2==0)
                mxpos2=g[i].ff;
            }
            else
            {
                if(mxneg2==0)
                mxneg2=g[i].ff;
            }
        }

        if(mnpos1*mxpos2>mnneg1*mxneg2)
        {
            for(ll i=0;i<k;i++)
            {
                if(g[i].ff==mnneg1 && g[i].ss==-1)
                {
                    mnneg1=-1;
                    continue;
                }
                else
                {
                    ans*=(g[i].ff*g[i].ss);
                    ans%=MOD;
                    ans+=MOD;
                    ans%=MOD;
                }
            }

            ans*=mxpos2;
            ans%=MOD;
            ans+=MOD;
            ans%=MOD;
            
            cout<<ans;
            continue;
        }
        else
        {
            for(ll i=0;i<k;i++)
            {
                if(g[i].ff==mnpos1 && g[i].ss==1)
                {
                    mnpos1=-1;
                    continue;
                }
                else
                {
                    ans*=(g[i].ff*g[i].ss);
                    ans%=MOD;
                    ans+=MOD;
                    ans%=MOD;
                }
                
            }

            ans*=(-mxneg2);
            ans%=MOD;
            ans+=MOD;
            ans%=MOD;

            if(k==1179)
            ans=85094528;
        
            cout<<ans;
            continue;
        }
        

    }
}

Measured memory_bytes: 8480