#include <bits/stdc++.h>
using namespace std;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    if (n == k) {
        Int res = 1;
        for (Int i = 0; i < (Int)n; i++) {
            res *= a[i];
            while (not (0 <= res and res < mod)) {
                res = (res + mod) % mod;
            }
        }
        print(res);
        return 0;
    }
    vector<Int> plus, minus, zero;
    for (Int i = 0; i < (Int)n; i++) {
        if (a[i] > 0) {
            plus.push_back(a[i]);
        } else if (a[i] < 0) {
            minus.push_back(a[i]);
        } else {
            zero.push_back(a[i]);
        }
    }
    sort(all(plus));
    sort(all(minus), greater<Int>());
    if (plus.empty()) {
        if ((Int)minus.size() < k) {
            print(0);
            return 0;
        }
        if (k % 2 == 0) {          
            Int res = 1;
            for (Int i = 0; i < k; i++) {
                res *= minus[minus.size() - 1 - i];
                while (not (0 <= res and res < mod)) {
                    res = (res + mod) % mod;
                }
            }
            print(res);
            return 0;
        }
        if (k % 2 == 1) {
            if (zero.empty()) {
                Int res = 1;
                for (Int i = 0; i < k; i++) {
                    res *= minus[i];
                    while (not (0 <= res and res < mod)) {
                        res = (res + mod) % mod;
                    }
                }
                print(res);
                return 0;
            } else {
                print(0);
                return 0;
            }
        }
    } else {
        if ((Int)minus.size() / 2 * 2 + (Int)plus.size() >= k) {
            Int res = 1;
            if (k % 2 == 1) {
                res *= plus.back();
                plus.pop_back();
                res %= mod;
                k--;
            }
            while (k > 0) {
                Int x = 0;
                if ((Int)minus.size() >= 2) {
                    x = minus[minus.size() - 1] * minus[minus.size() - 2];
                    // x %= mod;
                }
                Int y = 0;
                if ((Int)plus.size() >= 2) {
                    y = plus[plus.size() - 1] * plus[plus.size() - 2];
                    // y %= mod;
                }
                if (x >= y) {
                    x %= mod;
                    res *= x;
                    res %= mod;
                    minus.pop_back();
                    minus.pop_back();
                } else {
                    y %= mod;
                    res *= y;
                    res %= mod;
                    plus.pop_back();
                    plus.pop_back();
                }
                k -= 2;
            }
            print(res);
            return 0;
        } else {
            // 必ず 0 が存在するはず
            assert(not zero.empty());
            print(0);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 6904