#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int b[1000010];

ll sum1[1000005], sum2[1000005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<pair<int, int> > a;
    bool ok = 0;
    for(int i=0;i<n;i++){
        cin >> b[i];
        if(b[i] < 0) a.emplace_back(make_pair(-b[i], -1));
        else if(b[i] > 0) a.emplace_back(make_pair(b[i], 1));
        else ok = 1;
    }
    if((int)a.size() < k){
        printf("0\n");
        return 0;
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int cnt = 0;
    for(int i=0;i<k;i++){
        int v = a[i].first, d = a[i].second;
        if(d < 0) cnt++;
    }
    ll ans = 1;
    if(cnt%2 == 0){
        for(int i=0;i<k;i++){
            int v = a[i].first;
            if(a[i].second < 0) v = (-v+mod)%mod;
            ans = ans*1ll*v%mod;
        }
    }
    else{
        pair<int, int> ans1, ans2;
        bool ok1 = 0, ok2 = 0;
        ll res1 = 1, res2 = 1;
        for(int i=k-1;i>=0;i--){
            if(a[i].second < 0){
                for(int j=k;j<(int)a.size();j++){
                    if(a[j].second > 0){
                        ok1 = 1;
                        ans1 = make_pair(a[i].first, a[j].first);

                        break;
                    }
                }
                break;
            }
        }
        for(int i=k-1;i>=0;i--){
            if(a[i].second > 0){
                for(int j=k;j<(int)a.size();j++){
                    if(a[j].second < 0){
                        ok2 = 1;
                        ans2 = make_pair(a[i].first, a[j].first);
                        break;
                    }
                }
                break;
            }
        }
        if(ok1 && ok2){
            if(ans1.second*1ll*ans2.first > ans2.second*1ll*ans1.first){
                for(int i=k-1;i>=0;i--){
                    int v = a[i].first;
                    if(a[i].second < 0) v = (-v+mod)%mod;

                    if(a[i].second < 0){
                        ans = ans*1ll*ans1.second%mod;
                        for(int j=i-1;j>=0;j--){

                            int v = a[j].first;
                            if(a[j].second < 0) v = (-v+mod)%mod;

                            ans = ans*1ll*a[j].first%mod;
                        }
                        break;
                    }
                    ans = ans*1ll*v%mod;
                }
            }
            else{
                for(int i=k-1;i>=0;i--){
                    int v = a[i].first;
                    if(a[i].second < 0) v = (-v+mod)%mod;

                    if(a[i].second > 0){
                        ans = ans*1ll*(-ans2.second+mod)%mod;
                        for(int j=i-1;j>=0;j--){

                            int v = a[j].first;
                            if(a[j].second < 0) v = (-v+mod)%mod;

                            ans = ans*1ll*v%mod;
                        }
                        break;
                    }
                    ans = ans*1ll*v%mod;
                }
            }
        }
        else if(ok1){
                for(int i=k-1;i>=0;i--){
                    int v = a[i].first;
                    if(a[i].second < 0) v = (-v+mod)%mod;

                    if(a[i].second < 0){
                        ans = ans*1ll*ans1.second%mod;
                        for(int j=i-1;j>=0;j--){

                            int v = a[j].first;
                            if(a[j].second < 0) v = (-v+mod)%mod;

                            ans = ans*1ll*a[j].first%mod;
                        }
                        break;
                    }
                    ans = ans*1ll*v%mod;
                }
        }
        else if(ok2){
                for(int i=k-1;i>=0;i--){
                    int v = a[i].first;
                    if(a[i].second < 0) v = (-v+mod)%mod;

                    if(a[i].second > 0){
                        ans = ans*1ll*(-ans2.second+mod)%mod;
                        for(int j=i-1;j>=0;j--){

                            int v = a[j].first;
                            if(a[j].second < 0) v = (-v+mod)%mod;

                            ans = ans*1ll*v%mod;
                        }
                        break;
                    }
                    ans = ans*1ll*v%mod;
                }
        }
        else{
            if(ok) ans = 0;
            else{
                reverse(a.begin(), a.end());
                for(int i=0;i<k;i++){
                    int v = a[i].first;
                    if(a[i].second < 0) v = (-v+mod)%mod;
                    ans = ans*1ll*v%mod;
                }
            }
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 6132