#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

class ModInt {
public:
    long long x;
    constexpr ModInt(const long long x=0) : x((x+MOD)%MOD) {}
    constexpr ModInt& operator+=(const ModInt rhs) {
        x += rhs.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }
    constexpr ModInt operator+(const ModInt rhs) const {
        return ModInt(*this) += rhs; 
    }
    constexpr ModInt& operator-=(const ModInt& rhs) {
        x -= rhs.x;
        if (x < 0) x += MOD;
        return *this;
    }
    constexpr ModInt operator-(const ModInt rhs) const {
        return ModInt(*this) -= rhs; 
    }
    constexpr ModInt& operator*=(const ModInt& rhs) {
        x = x * rhs.x % MOD;
        return *this;
    }
    constexpr ModInt operator*(const ModInt rhs) const {
        return ModInt(*this) *= rhs; 
    }
    constexpr ModInt& operator/=(const ModInt& rhs) {
        ModInt div = powmod(rhs, MOD - 2);
        (x *= div.x) %= MOD;
        return *this;
    }
    constexpr ModInt operator/(const ModInt rhs) const {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt powmod(ModInt m, long long p) {
        if (p == 0) return ModInt(1);
        ModInt tmp = powmod(m, p / 2);
        if (p & 1) return tmp * tmp * m;
        else return tmp * tmp;
    }
    constexpr ModInt& operator++() {
        x += 1;
        return *this;
    }
    constexpr ModInt operator++(int) {
        ModInt tmp(*this);
        operator++();
        return tmp;
    }
    constexpr ModInt& operator--() {
        x -= 1;
        return *this;
    }
    constexpr ModInt operator--(int) {
        ModInt tmp(*this);
        operator--();
        return tmp;
    }

    friend ostream& operator<<(ostream& os, const ModInt &rhs) {
        os << rhs.x;
        return os;
    }
    friend istream& operator>>(istream& is, ModInt& rhs) {
        is >> rhs.x;
        return is;
    }
};
bool operator==(const ModInt& lhs, const ModInt& rhs) {
    return lhs.x == rhs.x;
}
bool operator!=(const ModInt& lhs, const ModInt& rhs) {
    return !(lhs == rhs);
}
ModInt powmod(ModInt m, long long p) {
    if (p == 0) return ModInt(1);
    ModInt tmp = powmod(m, p / 2);
    if (p & 1) return tmp * tmp * m;
    else return tmp * tmp;
}

using modi = ModInt;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n);
    vll ma, pa;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) ma.emplace_back(a[i]);
        else pa.emplace_back(a[i]);
    }

    if (n == k) {
        modi ans(1);
        for (ll i = 0; i < n; i++) ans *= modi(a[i]);
        cout << ans << '\n';
        return 0;
    }

    {
        if (pa.size() == 0) {
            if (k & 1) {
                sort(ALL(ma));
                reverse(ALL(ma));
                modi ans(1);
                for (ll i = 0; i < k; i++) ans *= modi(ma[i]);
                cout << ans << '\n';
            } else {
                sort(ALL(ma));
                modi ans(1);
                for (ll i = 0; i < k; i++) ans *= modi(ma[i]);
                cout << ans << '\n';
            }
        } else {
            sort(ALL(pa));
            sort(ALL(ma));
            reverse(ALL(ma));
            modi ans(1);

            for (ll k2 = k; k2 > 0;) {
                ll tmpp = -HIGHINF, tmpm = -HIGHINF;
                if (k2 > 1 && (int)pa.size() > 1) {
                    int sz = pa.size();
                    tmpp = pa[sz - 1] * pa[sz - 2];
                } else if ((int)pa.size() == 1 && (k2 & 1)) {
                    tmpp = pa.back();
                }

                if (k2 > 1 && (int)ma.size() > 1) {
                    int sz = ma.size();
                    tmpm = ma[sz - 1] * ma[sz - 2];
                }

                if (tmpp > tmpm || k2 == 1) {
                    ans *= modi(pa.back() % MOD);
                    pa.pop_back();
                    k2--;
                } else {
                    ma.pop_back(); ma.pop_back();
                    ans *= modi(tmpm % MOD);
                    k2 -= 2;
                }
            }
            cout << ans << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 6864