#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

const int mod=1e9+7;

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    vector<pair<int,int> >s;
    for(int i=1;i<=n;i++)
        s.push_back({abs(a[i]),a[i]});
    sort(s.begin(),s.end(),greater<>());
    int x=0;
    int y=0;
    int ans=1;
    for(int i=0;i<k;i++)
    {
        if(s[i].first==0)
        {
            cout<<0;
            return 0;
        }
        ans=(ans*s[i].first)%mod;
        if(s[i].second<0)
        {
            x++;
        }
        else
        {
            y++;
        }        
    }    

    if(x&1)
    {
        long double mx=0;
        int ind1=0,ind2=0;
        for(int i=k-1;i>=0;i--)
        {
            if(s[i].second<0)
            {
                for(int j=k;j<n;j++)
                {
                    if(s[j].second>=0)
                    {
                        long double tt=s[i].first;
                        if(mx<=(s[j].first)/tt)
                        {
                            mx=(s[j].first)/tt;
                            ind1=s[i].first;
                            ind2=s[j].first;
                        }
                        break;
                    }
                }
                break;
            }
        }
        for(int i=k-1;i>=0;i--)
        {
            if(s[i].second>0)
            {
                for(int j=k;j<n;j++)
                {
                    if(s[j].second<0)
                    {
                        long double tt=s[i].first;
                        if(mx<=(s[j].first)/tt)
                        {
                            mx=(s[j].first)/tt;
                            ind1=s[i].first;
                            ind2=s[j].first;
                        }
                        break;
                    }
                }
                break;
            }
        }
        if(ind1)
        {
            ans=(ans*power(ind1,mod-2,mod))%mod;
            ans=(ans*ind2)%mod;
        }
        else
        {
            ans=1;
            sort(s.begin(),s.end());
            for(int i=0;i<k;i++)
                ans=(ans*s[i].first)%mod;
            ans=mod-ans;
            ans%=mod;
        }
        cout<<ans;
    }
    else
    {
        cout<<ans;
    }
    

    
  
} 
    


Measured memory_bytes: 8912