/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
/*
    Use only when the modular is fixed;
    Computing inverse takes logN time so see whether to store it in a array;
*/
template <int mod = MOD>
struct Modular {
    int value;
    Modular(long long v = 0) {if(v >= MOD || v < -MOD) v %= MOD;value = v; if (value < 0) value += mod;}
    Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

    Modular& operator+=(Modular const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
    Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += mod;return *this;}
    Modular& operator*=(Modular const& b) {long long res = (long long)value * b.value;if(res >= MOD){res %= MOD;}value = res;return *this;}

    friend Modular mexp(Modular a, long long e) {
        e %= (mod - 1);
        Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
        return res;
    }
    friend Modular inverse(Modular a) { return mexp(a, mod - 2); }

    Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
    friend Modular operator+(Modular a, Modular const b) { return a += b; }
    friend Modular operator-(Modular a, Modular const b) { return a -= b; }
    friend Modular operator-(Modular const a) { return 0 - a; }
    friend Modular operator*(Modular a, Modular const b) { return a *= b; }
    friend Modular operator/(Modular a, Modular const b) { return a /= b; }
    friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
    friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
    friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

using Mint = Modular<>;
void solve() {
    int n, k;
    cin >> n >> k;
    vl arr(n);
    forn(i, n) {
        ll x;
        cin >> x;
        arr[i] = x;
    }
    sort(all(arr), [&](ll i, ll j) {
        return abs(i) > abs(j);
    });
    if(arr[k - 1] == 0) {
        cout << "0";
        return;
    }
    int sign = 1;
    Mint ans = 1;
    int rpos = -1, rneg = -1;
    forn(i, k) {
        if(arr[i] > 0)
            rpos = i;
        if(arr[i] < 0)
            rneg = i;
        sign *= arr[i] / abs(arr[i]);
        ans *= arr[i];
    }
    if(sign == 1) {
        cout << ans;
        return;
    }
    trace('a');
    int pos = -1, neg = -1;
    for(int i = k; i < n; i++) {
        if(arr[i] > 0 && pos == -1) {
            pos = i;
        }
        if(arr[i] < 0 && neg == -1) {
            neg = i;
        }
    }
    if(pos != -1 && rneg != -1) {
        if(neg != -1 && rpos != -1) {
            if(arr[neg] * arr[rneg] > arr[rpos] * arr[pos]) {
                ans /= arr[rpos];
                cout << ans * arr[neg];
            } else {
                ans /= arr[rneg];
                cout << ans * arr[pos];
            }
        } else {
            cout << (ans / arr[rneg]) * arr[pos];
        }
    } else if(rpos != -1 && neg != -1) {
        cout << (ans / arr[rpos]) * arr[neg];
    } else if(arr.back() == 0) {
        cout << 0;
    } else {
        trace("neg");
        // Negative
        Mint temp = 1;
        rforn(i, k) temp *= arr[i + n - k];
        cout << temp;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 4764