#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,k;
  cin>>n>>k;
  ll a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  int sei=0;
  int zero=0;
  int fu=0;
  rep(i,0,n){
    if(a[i]>0) sei++;
    else if(a[i]==0) zero++;
    else fu++;
  }
  
  if(k==n){
    if(zero!=0) cout<<0<<endl;
    else{
      ll ans=1;
      rep(i,0,n){
        ans*=abs(a[i]);
        ans%=mod;
      }
      if(fu%2==0) cout<<ans<<endl;
      else cout<<(mod-ans)%mod<<endl;
    }
    return 0;
  }
  if(k==n-1){
    if(zero>1) cout<<0<<endl;
    else if(zero==1){
      if(fu%2!=0) cout<<0<<endl;
      else{
        ll ans=1;
        rep(i,0,fu){
          ans*=a[i];
          ans%=mod;
        }
        rep(i,0,sei){
          ans*=a[n-1-i];
          ans%=mod;
        }
        cout<<ans<<endl;
      }
    }
    else{
      if(fu==0){
        ll ans=1;
        rep(i,0,k){
          ans*=a[n-1-i];
          ans%=mod;
        }
        cout<<ans<<endl;
      }
      else if(sei==0){
        if(k%2==0){
          ll ans=1;
          rep(i,0,k){
            ans*=-a[i];
            ans%=mod;
          }
          cout<<ans<<endl;
        }
        else{
          ll ans=1;
          rep(i,0,k){
            ans*=-a[fu-1-i];
            ans%=mod;
          }
          cout<<(mod-ans)%mod<<endl;
        }
      }
      else{
        if(fu%2==0){
          ll ans=1;
          rep(i,0,fu){
            ans*=-a[i];
            ans%=mod;
          }
          rep(i,0,sei-1){
            ans*=a[n-1-i];
            ans%=mod;
          }
          cout<<ans<<endl;
        }
        else{
          ll ans=1;
          rep(i,0,fu-1){
            ans*=-a[i];
            ans%=mod;
          }
          rep(i,0,sei){
            ans*=a[n-1-i];
            ans%=mod;
          }
          cout<<ans<<endl;
        }
      }
    }
    return 0;
  }
  if(zero==0){
    if(fu==0){
      ll ans=1;
      rep(i,0,k){
        ans*=a[n-1-i];
        ans%=mod;
      }
      cout<<ans<<endl;
    }
    else if(sei==0){
      if(k%2==0){
        ll ans=1;
        rep(i,0,k){
          ans*=-a[i];
          ans%=mod;
        }
        cout<<ans<<endl;
      }
      else{
        ll ans=1;
        rep(i,0,k){
          ans*=-a[fu-1-i];
          ans%=mod;
        }
        cout<<(mod-ans)%mod<<endl;
      }
    }
    else{
      if(k%2==0){
        priority_queue<ll> q;
        rep(i,0,sei/2){
          q.push(a[n-1-2*i]*a[n-1-2*i-1]);
        }
        rep(i,0,fu/2){
          q.push(a[2*i]*a[2*i+1]);
        }
        ll ans=1;
        rep(i,0,k/2){
          ll cur=q.top();
          q.pop();
          ans*=(cur%mod);
          ans%=mod;
        }
        cout<<ans<<endl;
      }
      else{
        priority_queue<ll> q;
        rep(i,0,(sei-1)/2){
          q.push(a[n-2-2*i]*a[n-2-2*i-1]);
        }
        rep(i,0,fu/2){
          q.push(a[2*i]*a[2*i+1]);
        }
        ll ans=a[n-1];
        rep(i,0,(k-1)/2){
          ll cur=q.top();
          q.pop();
          ans*=(cur%mod);
          ans%=mod;
        }
        cout<<ans<<endl;
      }
    }
  }
  else{
    if(sei+fu<k) cout<<0<<endl;
    else{
      if(fu==0){
        ll ans=1;
        rep(i,0,k){
          ans*=a[n-1-i];
          ans%=mod;
        }
        cout<<ans<<endl;
      }
      else if(sei==0){
        if(k%2==0){
          ll ans=1;
          rep(i,0,k){
            ans*=-a[i];
            ans%=mod;
          }
          cout<<ans<<endl;
        }
        else{
          /*ll ans=1;
          rep(i,0,k){
            ans*=-a[fu-1-i];
            ans%=mod;
          }
          cout<<(mod-ans)%mod<<endl;*/
          cout<<0<<endl;
        }
      }
      else{
        if(k%2==0){
          priority_queue<ll> q;
          rep(i,0,sei/2){
            q.push(a[n-1-2*i]*a[n-1-2*i-1]);
          }
          rep(i,0,fu/2){
            q.push(a[2*i]*a[2*i+1]);
          }
          ll ans=1;
          rep(i,0,k/2){
            ll cur=q.top();
            q.pop();
            ans*=(cur%mod);
            ans%=mod;
          }
          cout<<ans<<endl;
        }
        else{
          priority_queue<ll> q;
          rep(i,0,(sei-1)/2){
            q.push(a[n-2-2*i]*a[n-2-2*i-1]);
          }
          rep(i,0,fu/2){
            q.push(a[2*i]*a[2*i+1]);
          }
          ll ans=a[n-1];
          rep(i,0,(k-1)/2){
            ll cur=q.top();
            q.pop();
            ans*=(cur%mod);
            ans%=mod;
          }
          cout<<ans<<endl;
        }
      }
    }
  }
}

Measured memory_bytes: 5880