#include <bits/stdc++.h>                
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int M=1e9+7;
    int n,k;
    cin>>n>>k;
    vector <pair<long long int,int> > ls;
    long long int a[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=0) ls.push_back(make_pair(a[i],0));
        else ls.push_back(make_pair(-a[i],1));
    }
    sort(ls.begin(),ls.end(),greater<pair<long long int,int> >());
    long long int ans=1;
    int cnt=0;
    vector <long long int> positive;
    vector <long long int> negative;
    for (int i=0;i<k;i++){
        ans*=ls[i].first;
        ans%=M;
        cnt+=ls[i].second;
        if(ls[i].second==0) positive.push_back(ls[i].first);
        else negative.push_back(ls[i].first);
    }
    if(cnt%2){
        bool f1=false;
        long long int next_pos=-1;
        //case1 neg-- pos++
        if(negative.size()){
            for (int i=k;i<n;i++){
                if(ls[i].second==0){
                    next_pos=ls[i].first;
                    break;
                }
            }
            if(next_pos!=-1) f1=true;
        }    
        bool f2=false;
        long long int next_neg=-1;
        //case2 neg++ pos--
        if(positive.size()){
            for (int i=k;i<n;i++){
                if(ls[i].second==1){
                    next_neg=ls[i].first;
                    break;
                }
            }
            if(next_neg!=-1) f2=true;
        }    
        if(f1 and f2){
            long long int last_neg=negative[negative.size()-1];
            long long int last_pos=positive[positive.size()-1];
            if(next_pos*last_pos>=next_neg*last_neg){
                ans=next_pos;
                for (int i=0;i<(int)positive.size();i++){
                    ans*=positive[i];
                    ans%=M;
                }
                for (int i=0;i<(int)negative.size()-1;i++){
                    ans*=negative[i];
                    ans%=M;
                }
                cout<<ans<<"\n";
            }
            else{
                ans=next_neg;
                for (int i=0;i<(int)positive.size()-1;i++){
                    ans*=positive[i];
                    ans%=M;
                }
                for (int i=0;i<(int)negative.size();i++){
                    ans*=negative[i];
                    ans%=M;
                }
                cout<<ans<<"\n";
            }
        }
        else if(f1){
            ans=next_pos;
            for (int i=0;i<(int)positive.size();i++){
                ans*=positive[i];
                ans%=M;
            }
            for (int i=0;i<(int)negative.size()-1;i++){
                ans*=negative[i];
                ans%=M;
            }
            cout<<ans<<"\n";
        }
        else if(f2){
            ans=next_neg;
            for (int i=0;i<(int)positive.size()-1;i++){
                ans*=positive[i];
                ans%=M;
            }
            for (int i=0;i<(int)negative.size();i++){
                ans*=negative[i];
                ans%=M;
            }
            cout<<ans<<"\n";
        }
        else{
            sort(a,a+n,greater<long long int>());
            ans=1;
            for (int i=0;i<k;i++){
                ans*=a[i];
                ans%=M;
            }
            cout<<(ans+M)%M<<"\n";
        }
    }
    else cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 11524