#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>


#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long;

#define M (1'000'000'007)

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<pair<long, int>> ab;
    int zeros = 0;
    int t;

    for (int i = 0; i < n; i++) {
        cin >> t;
        if (t != 0)
            ab.emplace_back(abs(t), t >= 0 ? 1 : -1);
        else
            zeros++;
    }

    sort(ab.begin(), ab.end(), greater<pair<long, int>>());

    if (ab.size() < k) {
        cout << 0 << endl;
        return 0;
    }

    int negatives = 0;
    int lastNegativeIdx = -1;
    int lastPositiveIdx = -1;

    for (int i = 0; i < k; i++) {
        pair<long, int> p = ab[i];
        if (p.second == -1) {
            negatives++;
            lastNegativeIdx = i;
        } else {
            lastPositiveIdx = i;
        }
    }

    ll ans = 1;

    if (negatives % 2 == 0) {
        for (int i = 0; i < k; i++) {
            ans = ans * ab[i].first % M;
        }
        cout << ans << endl;
        return 0;
    } else {

        long lastNegative = 0;
        long lastPositive = 0;
        int nextNegativeIdx;
        int nextPositiveIdx;
        long nextNegative;
        long nextPositive;
        bool found1 = false;
        bool found2 = false;

        auto sol1 = [&]() {
            // multiply all idxes + lastNegativeIdx -> nextPositiveIdx
            for (int i = 0; i < k; i++) {
                if (i != lastNegativeIdx) {
                    ans = ans * ab[i].second * ab[i].first % M;
                } else {
                    ans = ans * ab[nextPositiveIdx].first % M;
                }
            }
            ans = (ans + M) % M;
            cout << ans << endl;
            return 0;
        };

        auto sol2 = [&]() {
            for (int i = 0; i < k; i++) {
                if (i != lastPositiveIdx) {
                    ans = ans * ab[i].second * ab[i].first % M;
                } else {
                    ans = ans * -1 * ab[nextNegativeIdx].first % M;
                }
            }
            ans = (ans + M) % M;
            cout << ans << endl;
            return 0;
        };

        // 1. replace lastNegativeIdx with the next positive
        if (lastNegativeIdx >= 0)
            lastNegative = ab[lastNegativeIdx].first * -1;
        for (int i = k; i < ab.size(); i++) {
            pair<long, int> p = ab[i];
            if (p.second == 1) {
                found1 = true;
                nextPositiveIdx = i;
                nextPositive = p.first;
                break;
            }
        }

        // 2. replace lastPositiveIdx with the next negative
        if (lastPositiveIdx >= 0)
            lastPositive = ab[lastPositiveIdx].first;
        if (negatives != k) {
            for (int i = k; i < ab.size(); i++) {
                pair<long, int> p = ab[i];
                if (p.second == -1) {
                    found2 = true;
                    nextNegativeIdx = i;
                    nextNegative = p.first * -1;
                    break;
                }
            }
        }

        if (found1 && found2) {
            if (lastPositiveIdx >= 0 && lastNegativeIdx >= 0 &&
                lastPositive * nextPositive > lastNegative * nextNegative) {
                return sol1();
            } else {
                return sol2();
            }
        } else if (found1) {
            return sol1();
        } else if (found2) {
            return sol2();
        }
        // 3. if 1 & 2 impossible, if zerox>0
        if (zeros > 0) {
            cout << 0 << endl;
            return 0;
        }
        // 4. else mul ab in reverse order
        sort(ab.begin(), ab.end());
        for (int i = 0; i < k; i++) {
            ans = ans * ab[i].first % M;
        }
        ans *= -1;
        ans = (ans + M) % M;
        cout << ans << endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 6996