#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;
int N, K;
ll mod = 1e9+7;
int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> N >> K;
    vector<ll> v(N);
    for(int i=0; i<N; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    //1 2 -3 -4
    //-4 -3 1 2
    //if we pick from left and numbers negative then we want 2 negative elements
    //base case k=1
    if(K==1) {
        ll res = v[N-1];
        while(res<0) res+=mod;
        
        cout << res%mod << "\n";
        return 0;
    }
    if(N==K) {
        ll res = 1;
        for(int i=0; i<N; i++) {
            res*=v[i];
            res%=mod;
        }
        while(res<0) res+=mod;
        cout << res%mod << "\n";
        return 0;
    }
    //we must always take an even number of negatives if possible
    vector<ll> neg;
    vector<ll> pos;
    for(int i=0; i<N; i++) {
        if(v[i]<0) {
            neg.push_back(v[i]);
        } else {
            pos.push_back(v[i]);
        }
    }
    sort(neg.begin(), neg.end());
    sort(pos.rbegin(), pos.rend());
    int p = 0, n=0;
    //-4 -3 1 2 3
    ll res = 1;
    //check if we HAVE to take an odd number of negatives
    if(pos.size()==0 && K%2==1) {
        for(int i = neg.size()-1; i>=0; i--) {
            if(K<=0) break;
            res*=neg[i];
            res%=mod;
            K--;
        }
        while(res<0) res+=mod;
        cout << res << "\n";
        return 0;
    }
    if(pos.size()>0 && K%2==1) {
        //add biggest positive number to sum
        res*=pos[p];
        res%=mod;
        p++;
        K--;
    }
    while(K>0) {
        //cout << K << ", " << res << "\n";
        //if we can include 2 elements
        //see if the product of 2 largest negatives or 2 largest positives is greater
        if(K>1) {
            int negleft = neg.size()-n;
            int posleft = pos.size()-p;
            if(posleft>1 && negleft>1) {
                //if k odd make take the larger positive number
                //after contest fix
                if(K%2==1) {
                    res*=pos[p];
                    res%=mod;
                    p++;
                    K--;
                    continue;
                }
                ll posprod = pos[p]*pos[p+1];
                ll negprod = neg[n]*neg[n+1];
                if(posprod>negprod) {
                    posprod%=mod;
                    res*=posprod;
                    res%=mod;
                    p+=2;
                    K-=2;
                } else {
                    negprod%=mod;
                    res*=negprod;
                    res%=mod;
                    n+=2;
                    K-=2;
                }
            } else if(negleft>1) {
                //decide whether to add positive number or not if possible
                if(posleft>0) {
                    //if k odd we should definitely include positive number, else we don't
                    if(K%2==1) {
                        res*=pos[p];
                        res%=mod;
                        p++;
                        K--;
                    } else {
                        //we don't include positive number or else we would include odd number of negatives
                        ll negprod = neg[n]*neg[n+1];
                        negprod%=mod;
                        res*=negprod;
                        res%=mod;
                        n+=2;
                        K-=2;
                    }
                } else {
                    ll negprod = neg[n]*neg[n+1];
                    negprod%=mod;
                    res*=negprod;
                    res%=mod;
                    n+=2;
                    K-=2;
                }
            } else if(posleft>1) {
                ll posprod = pos[p]*pos[p+1];
                posprod%=mod;
                res*=posprod;
                res%=mod;
                p+=2;
                K-=2;
            } else {
                //1 neg 1 pos left
                //pick pos
                res*=pos[p];
                res%=mod;
                p++;
                K--;
            }
        } else {
            //pick the largest element left
            if(p<pos.size()) {
                res*=pos[p];
                res%=mod;
                p++;
                K--;
            } else {
                //pick smallest magnitude negative
                res*=neg.back();
                res%=mod;
                K--;
            }
        }
    }
    while(res<0) res+=mod;
    cout << (res%mod) << "\n";
    return 0;
}


Measured memory_bytes: 7228