#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

int main()
{
  FAST/**/
   
   ll n,k;
   cin>>n>>k;
   
   pair<ll,ll> arr[n];
   rep(n)
   {
       cin>>arr[i].ff;
       ll sig = 1;
       if(arr[i].ff<0)
            sig = -1;
       arr[i] = mp(abs(arr[i].ff),sig);        
   }
   
   ll cn = 0;
   rep(n)
        if(arr[i].ss < 0)
            cn++;
   ll cp = n-cn;
   
   if(k == n)
   {
       ll ans = 1;
       rep(n)
       {
           ll sig = arr[i].ss;
           ans*=(arr[i].ff*sig);
           ans%=mod;
           if(ans<0)
                ans+=mod;
       }
       cout<<ans;
       return 0;
   }
   
   sort(arr,arr+n,greater<pair<ll,ll>>());
   
   if(cp == 0)
   {
       if(k%2 == 0)
       {
           ll ans = 1;
           rep(k)
           {
               ll sig = arr[i].ss;
               ans*=(arr[i].ff*sig);
               ans%=mod;
               if(ans<0)
                    ans+=mod;
           }
           cout<<ans;
           return 0;
       }
       
       reverse(arr,arr+n);
       ll ans = 1;
       rep(k)
       {
           ll sig = arr[i].ss;
           ans*=(arr[i].ff*sig);
           ans%=mod;
           if(ans<0)
                ans+=mod;
       }
      
       cout<<ans;
       return 0;
   }
   
   ll neg = 0;
   ll prod = 1;
   ll lasn = -inf;
   ll lasp = -inf;
   rep(k)
   {
       if(arr[i].ss<0)
            neg++, lasn = arr[i].ff;
       else lasp = arr[i].ff;        
       prod*=(arr[i].ff);
       prod%=mod;
   }
   
   if(neg%2 == 0)
   {
       cout<<prod;
       return 0;
   }
   
   ll subp = -inf, subn = -inf;
   for(ll i=k;i<n;i++)
   {
       if(subp == -inf && arr[i].ss>0)
           subp = arr[i].ff;
       if(subn == -inf && arr[i].ss<0)
            subn = arr[i].ff;
   }
   
   if(lasp == -inf){
       prod = (prod*powa(lasn,mod-2,mod))%mod;
       prod = (prod*subp)%mod;
       cout<<prod;
       return 0;
   }
   
   if(subp == -inf){
       prod = (prod*powa(lasp,mod-2,mod))%mod;
       prod = (prod*subn)%mod;
       cout<<prod;
       return 0;
   }
   
   if(subn == -inf){
       prod = (prod*powa(lasn,mod-2,mod))%mod;
       prod = (prod*subp)%mod;
       cout<<prod;
       return 0;
   }
   
   if(subp*lasp>subn*lasn)
   {
        prod = (prod*powa(lasn,mod-2,mod))%mod;
        prod = (prod*subp)%mod;
   }
   else
   {
       prod = (prod*powa(lasp,mod-2,mod))%mod;
       prod = (prod*subn)%mod;
   }
   
   cout<<prod;
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 6780