/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
ll x,y;
ll mm=1000000007;
void ext_euclid(ll m,ll c)
{
    if(c==0)
    {  
        x=1;
        y=0;
    }
    else
    {
        ext_euclid(c,m%c);
        int temp=x;
        x=y;
        y=temp-(m/c)*y;
    }
}
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      ll nn,k;cin>>nn>>k;ll arr[nn];inp(arr,nn);
      int cn=0,cp=0;priority_queue< ll > p,n;
      f(i,0,nn)
      {
        if(arr[i]>0)
        {
          cp++;p.push(arr[i]);
        }
        else
        {
          cn++;n.push(abs(arr[i]));
        }
        
      }
      if(k==nn)
      {
        ll ans=1;
        f(i,0,nn)
        {
          ans*=abs(arr[i]);
          ans%=mod;
        }
        if(cn%2)
        {
          ans*=-1;
          ans+=mod;
          ans%=mod;
        }
        cout<<ans;
        return 0;
      }
      if(cp==0)
      {
        if(k%2)
        {
          sort(arr,arr+nn);ll ans=1;
          for(int i=nn-1,c=1;i>=0 and c<=k;i--,c++)
          {
            ans*=abs(arr[i]);
            ans%=mod;
          }
          ans*=-1;
          ans+=mod;
          ans%=mod;
          cout<<ans;
        }
        else
        {
          sort(arr,arr+nn);ll ans=1;
          f(i,0,k)
          {
            ans*=abs(arr[i]);
            ans%=mod;
          }
          cout<<ans;
        }
        
      }
      else if(cn==0)
      {
        ll ans=1;
        sort(arr,arr+nn);
        for(int i=nn-1,c=1;i>=0 and c<=k;i--,c++)
          {
            ans*=abs(arr[i]);
            ans%=mod;
          }
          cout<<ans;
      }
      else
      {
        ll lp=-1,ln=-1;
        ll kk=k;
        ll ans=1;
        int cnt=0;
        while(kk--)
        {
          if(si(p)==0)
          {
            ll nn=n.top();
            cnt++;
            ans*=nn;
            ans%=mod;
            ln=nn;
            n.pop();
          }
          else if(si(n)==0)
          {
            ll pp=p.top();ans*=pp;ans%=mod;p.pop();lp=pp;
          }
          else
          {
            ll nn=n.top();ll pp=p.top();
            if(pp>nn)
            {
              ans*=pp;ans%=mod;lp=pp;p.pop();
            }
            else
            {
              ans*=nn;ans%=mod;ln=nn;n.pop();cnt++;
            }
            
          }
          
        }
        if(cnt%2)
        {
            ll val1=-1;
            if(si(n))
            {
              val1=n.top();
              val1*=ln;
              if(lp==-1)
              val1=-1;
            }
            ll val2=-1;
            if(si(p))
            {
              val2=p.top();
              val2*=lp;

            }
      
            if(val1==-1 and val2==-1)
            cout<<ans;
            else if(val1==-1)
            {
              ans*=p.top();
              ans%=mod;
              ext_euclid(ln,mod);
              x+=mod;
              x%=mod;
              ans*=x;
              ans%=mod;
              cout<<ans;
            }
            else if(val2==-1)
            {
              ans*=n.top();
              ans%=mod;
              ext_euclid(lp,mod);
              x+=mod;x%=mod;ans*=x;ans%=mod;cout<<ans;
            }
            else
            {
              if(val1>=val2)
              {
                ans*=n.top();
              ans%=mod;
              ext_euclid(lp,mod);
              x+=mod;x%=mod;ans*=x;ans%=mod;cout<<ans;
              }
              else
              {
                ans*=p.top();
              ans%=mod;
              ext_euclid(ln,mod);
              x+=mod;
              x%=mod;
              ans*=x;
              ans%=mod;
              cout<<ans;
              }
              
            }
            
        }
        else
        {
          
          cout<<ans;
        }
        
      }
      
    }    
} 


Measured memory_bytes: 6848