#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

const int MOD = 1e9 + 7;
void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
    }
    sort(arr.rbegin(), arr.rend(), [](int a, int b)->bool{return abs(a) < abs(b);});
    /*for(auto i : arr){*/
        /*cerr << i << " " ;*/
    /*}*/
    /*cerr << endl;*/
    int zeroes = 0;
    for(int i = 0; i < n; ++i){
        if(arr[i] == 0){
            ++zeroes;
        }
    }
    if(n - zeroes < k){
        cout << 0 << endl;
        return;
    }
    int neg = 0;
    int pos = 0;
    for(int i = 0; i < k; ++i){
        if(arr[i] < 0){
            ++neg;
        }
        if(arr[i] > 0){
            pos++;
        }
    }
    if(neg % 2 == 1){
        if(k + 1 <= (int)arr.size()){
            int pos_after = -1;
            int neg_before = -1;
            for(int j = k; j < n; ++j){
                if(arr[j] > 0){
                    pos_after = j;
                    break;
                }
            }
            if(pos_after != -1){
                for(int j = k - 1; j >= 0; --j){
                    if(arr[j] < 0){
                        neg_before = j;
                        break;
                    }
                }
            }
            int pos_before = -1;
            int neg_after = -1;
            for(int j = k - 1; j >= 0; --j){
                if(arr[j] > 0){
                    pos_before = j;
                    break;
                }
            }
            if(pos_before != -1){
                for(int j = k; j < n; ++j){
                    if(arr[j] < 0){
                        neg_after = j;
                        break;
                    }
                }
            }
            /*debug(pos_after);*/
            /*debug(neg_before);*/
            /*debug(pos_before);*/
            /*debug(neg_after);*/
            if(pos_after != -1 && neg_before != -1 && pos_before != -1 && neg_after != -1){
                if(1LL * arr[pos_after] * arr[pos_before] > 1LL * arr[neg_after] * arr[neg_before]){
                    swap(arr[pos_after], arr[neg_before]);
                }
                else {
                    swap(arr[neg_after], arr[pos_before]);
                }
            }
            else if(pos_after != -1 && neg_before != -1){
                swap(arr[pos_after], arr[neg_before]);
            }
            else if(pos_before != -1 && neg_after != -1){
                swap(arr[neg_after], arr[pos_before]);
            }
            else {
                reverse(arr.begin(), arr.end());
            }
        }
    }
    ll ans = 1;
    auto mult = [](int a, int b)->ll{
        a = (MOD + (a % MOD)) % MOD;
        b = (MOD + (b % MOD)) % MOD;
        /*return a * b;*/
        return 1LL * a  * b % MOD;
    };
    auto modify = [&](int element) -> void {
        ans = mult(ans, element);
    };
    for_each(arr.begin(), arr.begin() + k, modify);
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    t = 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3988