#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

const int mod = 1e9+7;

int n,k,a[200005],prod;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    if(k == n){
        int prod = 1;
        for(int i=1;i<=n;i++){
            prod = (prod * a[i]) % mod;
        }
        while(prod < 0LL){
            prod = (prod + mod) % mod;
        }
        rc(prod);
    }
    else{
        if(a[n] < 0LL){
            int prod = 1;
            if(k%2 == 0){
                for(int i=1;i<=k;i++){
                    prod = (prod * a[i]) % mod;
                }
                rc(prod);
            }
            else{
                for(int i=n;i>=n-k+1;i--){
                    prod = (prod * a[i]) % mod;
                }
                while(prod < 0LL){
                    prod = (prod + mod) % mod;
                }
                rc(prod);
            }
        }
        else{
            vector<int>neg;
            vector<int>poz;
            int prod = 1;
            if(k % 2 == 1){
                --k;
                prod = (prod * a[n]) % mod;
                --n;
            }
            for(int i=1;i<=n;i++){
                if(a[i] < 0) neg.push_back(a[i]);
                else{
                    poz.push_back(a[i]);
                }
            }
            reverse(all(neg));
            while(k){
                k--;
                k--;
                if((int)poz.size() >= 2LL && (int)neg.size() >= 2LL){
                    int curr1 = poz.back() * poz[(int)poz.size() - 2];
                    int curr2 = neg.back() * neg[(int)neg.size() - 2];
                    if(curr1 > curr2){
                        prod = prod * poz.back() % mod;
                        poz.pop_back();
                        prod = prod * poz.back() % mod;
                        poz.pop_back();
                    }
                    else{
                        prod = prod * neg.back() % mod;
                        neg.pop_back();
                        prod = prod * neg.back() % mod;
                        neg.pop_back();
                    }
                }
                else{
                    if((int)poz.size() >= 2LL){
                        prod = prod * poz.back() % mod;
                        poz.pop_back();
                        prod = prod * poz.back() % mod;
                        poz.pop_back();
                    }
                    else{
                        prod = prod * neg.back() % mod;
                        neg.pop_back();
                        prod = prod * neg.back() % mod;
                        neg.pop_back();
                    }
                }
            }
            rc(prod);
        }
    }
}


Measured memory_bytes: 7104