// #define INTERACTIVE
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // gp_hash_table<int, int> == hash map
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
template <typename K, typename V> using hashmap = gp_hash_table<K, V>;

template<typename A, typename B> ostream& operator<<(ostream& out, pair<A, B> p) { out << "(" << p.first << ", " << p.second << ")"; return out;}
template<typename T> ostream& operator<<(ostream& out, vector<T> v) { out << "["; for(auto& x : v) out << x << ", "; out << "]";return out;}
template<typename T> ostream& operator<<(ostream& out, deque<T> v) { out << "["; for(auto& x : v) out << x << ", "; out << "]";return out;}
template<typename T> ostream& operator<<(ostream& out, set<T> v) { out << "{"; for(auto& x : v) out << x << ", "; out << "}"; return out; }
template<typename K, typename V> ostream& operator<<(ostream& out, map<K, V> m) { out << "{"; for(auto& e : m) out << e.first << " -> " << e.second << ", "; out << "}"; return out; }
template<typename K, typename V> ostream& operator<<(ostream& out, hashmap<K, V> m) { out << "{"; for(auto& e : m) out << e.first << " -> " << e.second << ", "; out << "}"; return out; }

template<typename T> T read() {T x;cin >> x;return x;}
template<typename T> vector<T> read(int n) {vector<T> v(n);for(auto& x : v) cin >> x;return v;}
template<typename A, typename B>istream& operator>>(istream& in, pair<A, B>& p) {return in >> p.first >> p.second;}
template<class... Args> auto createVec(size_t n, Args&&... args) { if constexpr(sizeof...(args) == 1) return vector(n, args...); else return vector(n, create(args...)); }

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define TESTS(t) int NUMBER_OF_TESTS; cin >> NUMBER_OF_TESTS; for(int t = 1; t <= NUMBER_OF_TESTS; t++)
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define sgn(a)     ((a) > eps ? 1 : ((a) < -eps ? -1 : 0))
#define precise(x) fixed << setprecision(x)
#define all(a) a.begin(), a.end()
#define pb push_back
#define rnd(a, b) (uniform_int_distribution<int>((a), (b))(rng))
#ifndef LOCAL
    #define cerr if(0)cout
    #ifndef INTERACTIVE
        #define endl "\n"
    #endif
    #define debug(args...) if(0){}
#else
    #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg(_it, true, args); }
    void dbg(istream_iterator<string> it, bool isStart) {cerr << "</debug>" << endl;}
    template<typename T, typename... Args>
    void dbg(istream_iterator<string> it, bool isStart, T a, Args... args) {
        if(isStart) cerr << "<debug>" << endl;
        cerr << "  " << *it << " = " << a << endl;
        dbg(++it, false, args...);
    }
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
std::chrono::steady_clock::time_point __clock__;
void startTime() {__clock__ = std::chrono::steady_clock::now();}
ld getTime() {
    auto end = std::chrono::steady_clock::now();
    auto t = std::chrono::duration_cast<std::chrono::microseconds> (end-__clock__).count();
    return ld(t)/1e6;
}
void timeit(string msg) {
    cerr << "> " << msg << ": " << precise(6) << getTime() << endl;
}
template<typename T> inline bool maxi(T& a, T b) { return b > a ? (a = b, true) : false; }
template<typename T> inline bool mini(T& a, T b) { return b < a ? (a = b, true) : false; }
const ld PI = asin(1) * 2;
const ld eps = 1e-6;
const int oo = 2e9;
const ll OO = 2e18;
const ll MOD = 1000000007;
const int MAXN = 200000;

int main()
{
    FAST_IO;
    startTime();
    
    int n, k;
    cin >> n >> k;
    vector<ll> arr(n);
    for(auto& x : arr) cin >> x;

    if (k == n) {
        ll ans = 1;
        for(auto x : arr) {
            ans *= x;
            ans %= MOD;
        }
        if (ans < 0) ans += MOD;
        cout << ans << endl;
        exit(0);
    }

    vector<ll> negs, poss, zeros;
    for(auto x : arr) {
        if (x < 0) negs.pb(x);
        else if(x > 0) poss.pb(x);
        else zeros.pb(x);
    }

    if (poss.empty()) {
        sort(all(arr)); // -4, -3, -2, ...
        if (k%2 == 1) reverse(all(arr)); // 0, -1, -2, ...
        ll ans = 1;
        FOR(i, 0, k) {
            ans *= arr[i];
            ans %= MOD;
        }
        if (ans < 0) ans += MOD;
        cout << ans << endl;
        exit(0);
    }
    if (negs.empty()) {
        sort(all(arr));
        reverse(all(arr));
        ll ans = 1;
        FOR(i, 0, k) {
            ans *= arr[i];
            ans %= MOD;
        }
        if (ans < 0) ans += MOD;
        cout << ans << endl;
        exit(0);
    }
    if (n - (int)zeros.size() < k) {
        cout << 0 << endl;
        exit(0);
    }

    // k < n, at least 1 positive number, at least 1 negative number
    vector<pair<pair<ll, int>, pll>> grouped;
    for(auto z : zeros) negs.pb(z);
    sort(all(negs)); // -4, -3, ...
    sort(all(poss)); reverse(all(poss)); // 10, 9, 8, ...
    for(int i = 0; i < (int)negs.size(); i += 2) {
        ll val = negs[i];
        int sz = 1;
        pll made = {-1, -1};
        if (i+1 < (int)negs.size()) {
            val *= negs[i+1];
            sz++;
            made = {-negs[i], -negs[i+1]};
        }
        grouped.pb({{val, sz}, made});
    }
    for(int i = 0; i < (int)negs.size(); i++) grouped.pb({{negs[i], 1}, {-1, -1}});
    for(int i = 0; i < (int)poss.size(); i += 2) {
        ll val = poss[i];
        int sz = 1;
        pll made = {-1, -1};
        if (i+1 < (int)poss.size()) {
            val *= poss[i+1];
            sz++;
            made = {-poss[i], -poss[i+1]};
        }
        grouped.pb({{val, sz}, made});
    }
    for(int i = 0; i < (int)poss.size(); i++) grouped.pb({{poss[i], 1}, {-1, -1}});
    sort(all(grouped));
    reverse(all(grouped));
    ll ans = 1;
    map<ll, int> forbid;
    for(auto p : grouped) {
        ll v = p.first.first;
        pll made = p.second;
        int cnt = p.first.second;
        if (k >= cnt) {
            if (cnt == 1 && forbid.count(v) > 0) {
                forbid[v]--;
                if (forbid[v] == 0) forbid.erase(v);
                continue;
            }
            k -= cnt;
            ans *= (v%MOD);
            ans %= MOD;
            if (cnt == 2) {
                forbid[-made.first]++;
                forbid[-made.second]++;
            }
        }
    }
    assert(k == 0);
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    



    timeit("Finished");
    return 0;
}

Measured memory_bytes: 24656