#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define vpli vector<pair<long long,int>>
#define deb(x) cout<<x<<endl;
ll MOD = 1e9+7;

ll bpow(ll n,ll m)
{
  if(m==0) return 1;
  ll ans = bpow(n,m/2);
  ans = (ans*ans)%MOD;
  if(m%2 == 1) ans = (ans*n)%MOD;
  return ans;
}

ll inverse(ll n)
{
  return bpow(n,MOD-2);
}

ll mulmod(ll a,ll b)
{
  return (((a+MOD)%MOD)*((b+MOD)%MOD)+MOD)%MOD;
}

ll mulmod(ll a,ll b,ll c)
{
  return mulmod(mulmod(a,b),c);
}

void solve()
{
  ll n,k;
  cin>>n>>k;
  vll pos,neg;
  ll temp;
  for(ll i=0;i<n;i++)
  {
    cin>>temp;
    if(temp>=0) pos.pb(temp);
    else neg.pb(temp);
  }
  ll prod = 1;
  if(n==k)
  {
    for(ll x : pos) prod = mulmod(prod,x);
    for(ll x : neg) prod = mulmod(prod,x);
    cout<<prod<<"\n";
    return;
  }
  sort(pos.begin(),pos.end());
  reverse(pos.begin(),pos.end());
  sort(neg.begin(),neg.end());
  // all pos numbers
  if(neg.size() == 0)
  {
    for(ll i=0;i<k;i++)
    {
      prod = mulmod(prod,pos[i]);
    }
    cout<<prod<<"\n";
    return;
  }
  // all negative numbers
  if(pos.size() == 0)
  {
    if(k%2)
    {
      for(ll i=n-k;i<n;i++)
        prod = mulmod(prod,neg[i]);
    }
    else
    {
      for(ll i=0;i<k;i++)
        prod = mulmod(prod,neg[i]);
    }
    cout<<prod<<"\n";
    return;
  }
  // mixed with k<pos.size() + neg.size() && pos.size>=1 && neg.size()>=1
  if(k%2)
  {
    ll posix,negix;
    if(pos.size()%2)
    {
      posix=min((ll)pos.size(),k);
      /*
      for(posix=0;posix<=min((ll)pos.size()-1,k-1);posix++)
      {
        prod = mulmod(prod,pos[posix]);
      }
      */
    }
    else
    {
      posix=min((ll)pos.size()-1,k);
      /*
      for(posix=0;posix<=min((ll)pos.size()-2,k-1);posix++)
      {
        prod = mulmod(prod,pos[posix]);
      }
      */
    }
    negix = k-posix;
    /*
    for(negix=0;negix<rem;negix++)
    {
      prod = mulmod(prod,-1*neg[negix]);
    }
    ll tempprod = prod;
    */
    while(posix>1 && negix<neg.size()-1 && neg[negix]*neg[negix+1] > pos[posix-1]*pos[posix-2])
    {
      posix -= 2;
      negix += 2;
    }
    //deb(posix);
    //deb(negix);
    for(ll i=0;i<posix;i++)
    {
      prod = mulmod(prod,pos[i]);
    }
    for(ll i=0;i<negix;i++)
    {
      prod = mulmod(prod,neg[i]);
    }
    cout<<prod<<"\n";
    return;
  }
  else
  {
    //k is even
    if(pos.size() == 1)
    {
      prod = mulmod(prod,pos[0]);
      for(ll i=neg.size()-k+1;i<neg.size();i++)
      {
        prod = mulmod(prod,neg[i]);
      }
      prod=mulmod(prod,-1);
      cout<<prod<<"\n";
      return;
    }
    ll posix,negix;
    posix = min(((ll)pos.size()/2)*2,k);
    /*
    for(posix = 0;posix < min(((ll)pos.size()/2)*2,k);posix++)
    {
      prod = mulmod(prod,pos[posix]);
    }
    */
    //deb(prod);
    negix = k-posix;
    /*
    for(negix = 0;negix<rem;negix++)
    {
      prod = mulmod(prod,-1*neg[negix]);
    }
    */
    //deb(prod);
    //ll tempprod=prod;
    while(posix>1 && negix<neg.size()-1 && neg[negix]*neg[negix+1] > pos[posix-1]*pos[posix-2])
    {
      posix -= 2;
      negix += 2;
    }
    for(ll i=0;i<posix;i++)
    {
      prod = mulmod(prod,pos[i]);
    }
    for(ll i=0;i<negix;i++)
    {
      prod = mulmod(prod,neg[i]);
    }
    cout<<prod<<"\n";
    return;
  }

}

int main()
{
  solve();
  //cout<<mulmod(mulmod(1e9,1e9,1e9),1e9,mulmod(-1e9,-1e9))<<endl;
  return 0;
}



Measured memory_bytes: 5416