//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

ll multiply(ll a, ll b){
    return (a*b)%mod;
}

void print(ll ans){
    cout<<(ans%mod+mod)%mod<<endl;
}

bool comp(ll& a, ll& b){
    if(llabs(a)==llabs(b)){
        return a>b;
    }
    else{
        return llabs(a)>llabs(b);
    }
}

int main(){
    cpp();
    ll n, k;
    cin>>n>>k;
    vector<ll> v(n);
    for(ll i=0; i<n; i++) cin>>v[i];
    if(k==n){
        ll prod = 1;
        for(auto i: v) prod=multiply(prod, i);
        print(prod);
        return 0;
    }
    ll hasPos = 0;
    for(ll i: v) if(i>=0) hasPos=1;
    if(!hasPos){
        sort(v.begin(), v.end());
        if(k%2){
            ll prod = 1;
            for(ll i=0; i<k; i++){
                prod = multiply(prod, v[n-1-i]);
            }
            print(prod);
            return 0;
        }
        ll prod = 1;
        for(ll i=0; i<k; i++){
            prod=multiply(prod, v[i]);
        }
        print(prod);
        return 0;
    }
    sort(v.begin(), v.end(), comp);
    ll prod = 1;
    ll lastNeg;
    ll lastPos;
    ll isPos = 0;
    for(ll i=0; i<k; i++){
        if(v[i]<0) lastNeg = v[i];
        if(v[i]>=0) lastPos = v[i];
        if(v[i]>=0) isPos = 1;
        prod = multiply(prod, v[i]);
    }
    if(prod>=0){
        print(prod);
        return 0;
    }
    if(!isPos){
        ll prods = 1;
        ll idx = find(v.begin(), v.end(), lastNeg) - v.begin();
        for(ll i=0; i<k; i++){
            if(i!=idx){
                prods = multiply(prods, v[i]);
            }
        }
        ll nextPos=0;
        for(ll i=k; i<n; i++){
            if(v[i]>=0){
                nextPos = v[i];
                break;
            }
        }
        prods=multiply(prods, nextPos);
        print(prods);
        return 0;
    }
    ll nextPos = INT_MAX;
    ll nextNeg = INT_MAX;
    for(ll i=k; i<n; i++){
        if(v[i]>=0){
            nextPos = v[i];
            break;
        }
    }
    for(ll i=k; i<n; i++){
        if(v[i]<0){
            nextNeg = v[i];
            break;
        }
    }
    if(nextPos==INT_MAX){
        ll prods = 1;
        ll idx = find(v.begin(), v.end(), lastPos) - v.begin();
        for(ll i=0; i<k; i++){
            if(i!=idx){
                prods = multiply(prods, v[i]);
            }
        }
        ll nextNegss=0;
        for(ll i=k; i<n; i++){
            if(v[i]<0){
                nextNegss = v[i];
                break;
            }
        }
        prods=multiply(prods, nextNegss);
        print(prods);
        return 0;
    }
    else if(nextNeg==INT_MAX){
        ll prods = 1;
        ll idx = find(v.begin(), v.end(), lastNeg) - v.begin();
        for(ll i=0; i<k; i++){
            if(i!=idx){
                prods = multiply(prods, v[i]);
            }
        }
        ll nextPoss=0;
        for(ll i=k; i<n; i++){
            if(v[i]>=0){
                nextPoss = v[i];
                break;
            }
        }
        prods=multiply(prods, nextPoss);
        print(prods);
        return 0;
    }
    else{
        if(llabs(lastPos*nextPos)>llabs(lastNeg*nextNeg)){
            ll prods = 1;
            ll idx = find(v.begin(), v.end(), lastNeg) - v.begin();
            for(ll i=0; i<k; i++){
                if(i!=idx){
                    prods = multiply(prods, v[i]);
                }
            }
            ll nextPoss=0;
            for(ll i=k; i<n; i++){
                if(v[i]>=0){
                    nextPoss = v[i];
                    break;
                }
            }
            prods=multiply(prods, nextPoss);
            print(prods);
            return 0;
        }
        else{
            ll prods = 1;
            ll idx = find(v.begin(), v.end(), lastPos) - v.begin();
            for(ll i=0; i<k; i++){
                if(i!=idx){
                    prods = multiply(prods, v[i]);
                }
            }
            ll nextNegss=0;
            for(ll i=k; i<n; i++){
                if(v[i]<0){
                    nextNegss = v[i];
                    break;
                }
            }
            prods=multiply(prods, nextNegss);
            print(prods);
            return 0;
        }
    }
    return 0;
}









Measured memory_bytes: 4764