#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n, k;
vector <int> pos, neg;
int POW(int u, int v) {
    if (v==0) return 1;
    int mid = POW(u, v/2);
    mid = (mid*mid)%mod;
    if (v%2==0) return mid;
    else return (mid*u)%mod;
}
// main solution goes here:
void execute(int test_number)
{
    cin>>n>>k;
    int u;
    for (int i=1; i<=n; i++) {
        cin>>u;
        if (u>0) pos.push_back(u);
        else neg.push_back(u);
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    if (k == n ){
        int ans = 1;
        for (int i: pos) ans = (ans * i)%mod;
        for (int i: neg) ans = ((ans * i) % mod + mod)%mod;
        cout<<ans<<"\n";
    }
    else if (pos.size() == 0) {
        if (k%2==0) {
            int ans = 1;
            for (int i=0; i < k; i++) {
                ans = ((ans*neg[i])%mod + mod) % mod;
            }
            cout<<ans<<"\n";
        } else {
            int ans = 1;
            for (int i=(int)neg.size() - 1; i >= (int)neg.size() - k; i--) {
                ans = ((ans*neg[i])%mod + mod) % mod;
            }
            cout<<ans<<"\n";
        }
    } else {
        int ans = -inf;
        vector <int> posrev={};
        for (int i = 0; i <= min((int)neg.size(), k); i+=2)  {
            
            if (k-i > (int)pos.size()) continue;
            if (ans == -inf) {
                ans = 1;
                for (int j = 0; j<i; j++) ans = ((ans*neg[j])%mod+mod)%mod;
                for (int j = (int)pos.size() - 1; j >= (int)pos.size() - (k-i); j--) {
                    // cerr<<"iter "<<j<<"\n";s
                    ans = ((ans*pos[j])%mod+mod)%mod;
                    posrev.push_back(pos[j]);
                }
                continue;
            }
            // cerr<<lst<<" "<<neg[i-1] * neg[i-2]<<"\n";
            int lst = posrev[posrev.size()-1] * posrev[posrev.size() - 2];
            if (lst <= neg[i-1] * neg[i-2]) {
                lst = lst%mod;
                int t = (neg[i-2] * neg[i-1])%mod;
                // cerr<<ans<<"\n";
                ans = (ans*t)%mod;
                // cerr<<ans<<"\n";
                ans = (ans*POW(lst, mod-2))%mod;
                posrev.pop_back();
                posrev.pop_back();
            }
            else break;
        }
        cout<<ans;
    }
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 7884