#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
vector<ll> a;

ll solve() {
    if (k == n) {
        ll res = 1;
        for (int i = 0; i < n; i++) {
            res *= (a[i] + mod) % mod;
            res %= mod;
        }
        return res;
    }
    
    sort(ALL(a), [](const ll x, const ll y){ return abs(x) > abs(y); });
    int neg = 0;
    for (int i = 0; i < k; i++) {
        if (a[i] < 0)
            neg++;
    }
    if (neg % 2 == 0) {
        ll res = 1;
        for (int i = 0; i < k; i++) {
            res *= abs(a[i]);
            res %= mod;
        }
        return res;
    } else {
        if (a[k-1] == 0) return 0;
        if (a[k-1] > 0) {
            ll b = 0;
            int skip = -1;
            for (int i = k; i < n; i++) {
                if (a[i] < 0) {
                    b = a[i];
                    skip = k-1;
                    break;
                }
            }
            ll res0 = 0;
            ll a0 = abs(b), b0 = abs(a[k-1]);
            if (skip >= 0) {
                res0 = abs(b);
                for (int i = 0; i < k-1; i++) {
                    res0 *= abs(a[i]);
                    res0 %= mod;
                }
            }
            for (int i = k-1; i >= 0; i--) {
                if (a[i] < 0) {
                    skip = i;
                    break;
                }
            }
            ll res = a[k];
            for (int i = 0; i < k; i++) {
                if (i == skip) continue;
                res *= abs(a[i]);
                res %= mod;
            }
            return (a0 * abs(a[skip]) >= abs(a[k]) * b0 ? res0 : res);
        } else {
            ll b = 0;
            int skip = -1;
            for (int i = k; i < n; i++) {
                if (a[i] > 0) {
                    b = a[i];
                    skip = k-1;
                    break;
                }
            }
            ll res0 = 0;
            ll a0 = abs(b), b0 = abs(a[k-1]);
            bool f = false;
            if (skip >= 0) {
                res0 = abs(b);
                for (int i = 0; i < k-1; i++) {
                    res0 *= abs(a[i]);
                    res0 %= mod;
                }
                f = true;
            }
            skip = -1;
            for (int i = k-1; i >= 0; i--) {
                if (a[i] > 0) {
                    skip = i;
                    break;
                }
            }
            if (skip < 0 && f) return res0;
            if (skip >= 0) {
                ll res = abs(a[k]);
                for (int i = 0; i < k; i++) {
                    if (i == skip) continue;
                    res *= abs(a[i]);
                    res %= mod;
                }
                return (a0 * abs(a[skip]) >= abs(a[k]) * b0 ? res0 : res);
            } else {
                ll res = 1;
                for (int i = n-1; i >= n-k; i--) {
                    res *= (a[i] + mod) % mod;
                    res %= mod;
                }
                return res;
            }
        }
    }
}

void input() {
    cin >> n >> k;
    a = vector<ll>(n);
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 4720