#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = 2e5+10, inf = 1000111222;
const int md=1e9+7;

int a[max_n];

ll get_two_last(vector<int>& a)
{
    return 1ll*a.back()*1ll*a[a.size()-2];
}

int main() {
//    freopen("barik.in", "r", stdin);
//    freopen("barik.out", "w", stdout);

    int n,k;
    cin>>n>>k;
    vector<int> plus(0);
    vector<int> minus(0);
    bool any_zero=0;
    for (int i=0;i<n;i++){
        int a;
        cin>>a;
        if (a==0){
            any_zero=1;
        }
        else if (a>0){
            plus.pb(a);
        }
        else if (a<0){
            minus.pb(a);
        }
        else{
            assert(0);
        }
    }
    // make positive answer
    if (plus.size()+minus.size()>=k){
        if (plus.size()>=k || (k%2==0 && ((int)plus.size()-(int)plus.size()%2+(int)minus.size()-(int)minus.size()%2)>=k)
        || (k%2==1 && plus.size()>=1 && ((int)(plus.size()-1)-(int)(plus.size()-1)%2+(int)minus.size()-(int)minus.size()%2)>=k-1)){
            sort(all(plus));
            sort(all(minus));
            reverse(all(minus));
            int taken=0;
            ll ans=1;
            if (k%2==1){
                assert(plus.size()>=1);

                ans=(ans*plus.back()%md+md)%md;
                plus.pop_back();

                taken+=1;
            }
            while (taken<k){
                if (taken+2<=k && minus.size()>=2 && ((plus.size()>=2 && get_two_last(plus)<=get_two_last(minus)) || plus.size()<=1)){
                    ans=(ans*minus.back()%md+md)%md;
                    minus.pop_back();
                    ans=(ans*minus.back()%md+md)%md;
                    minus.pop_back();

                    taken+=2;
                }
                else{
                    ans=(ans*plus.back()%md+md)%md;
                    plus.pop_back();
                    ans=(ans*plus.back()%md+md)%md;
                    plus.pop_back();

                    taken+=2;
                }
            }
            cout<<ans<<"\n";
            return 0;
        }
    }

    // make zero
    if (any_zero){
        cout<<0<<"\n";
        return 0;
    }

    // make_negative
    {
        vector<int> alls;
        for (auto i:plus){
            alls.pb(abs(i));
        }
        for (auto i:minus){
            alls.pb(abs(i));
        }
        sort(all(alls));
        ll ans=1;
        for (int i=0;i<k;i++){
            ans=(ans*alls[i]%md+md)%md;
        }
        cout<<(-ans+md)%md<<"\n";
        return 0;
    }
}


Measured memory_bytes: 5032