#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define tri pair<pll, ll>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
// #define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);} 
ll inverse(ll a)    {return cinv(a, MOD);}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, k;
        cin>>n>>k;
        vlp vec(n);
        ll x, y;
        ll cz = 0, cp = 0, cn = 0;
        rep(i, n){
            cin>>x;
            vec[i] = {abs(x), x};
            if(x == 0)  cz++;
            else if(x > 0) cp++;
            else cn++;
        }
        if(cz + k > n){
            cout<<0; return 0;
        }
        sort(all(vec));
        reverse(all(vec));
        ll neg = 0, mn = 1, mp = -1;
        ll prod = 1;
        rep(i, k){
            if(vec[i].sec < 0){
                neg++; 
                if(mn == 1) mn = vec[i].sec;
                else mn = max(mn, vec[i].sec);
            }else{
                if(mp == -1)    mp = vec[i].sec;
                else mp = min(mp, vec[i].sec);       
            }
            prod *= vec[i].sec;
            prod = modify(prod);
        }
        if(neg % 2 == 0){
            cout<<prod; return 0;
        }
        x = 0, y = 0;
        foi(i, k, n){
            if(vec[i].sec > 0 && x == 0)  x = vec[i].sec;
            if(vec[i].sec < 0 && y == 0)  y = vec[i].sec;
        }
        // cout<<x<<" "<<y<<" "<<mn<<" "<<mp<<endl;
        if((x == 0 || mn == 1) && (y == 0 || mp == -1)){
            if(cz > 0)  cout<<0;
            else{
                reverse(all(vec));
                prod = 1;
                rep(i, k)   {prod *= vec[i].sec; prod = modify(prod);}
                cout<<prod;
            }
        }else if(!(x == 0 || mn == 1) && !(y == 0 || mp == -1)){
            if(abs(mp)*abs(x) >= abs(y)*abs(mn)){
                prod *= inverse(modify(mn));
                prod = modify(prod);
                prod *= abs(x);
                prod = modify(prod);
            }else{
                prod *= inverse(modify(mp));
                prod = modify(prod);
                prod *= y;
                prod = modify(prod);
            }
            cout<<prod;
        }else if(!(x == 0 || mn == 1)){
            prod *= inverse(modify(mn));
            prod = modify(prod);
            prod *= abs(x);
            prod = modify(prod);
            cout<<prod;
        }else{
            prod *= inverse(modify(mp));
            prod = modify(prod);
            prod *= y;
            prod = modify(prod);
            cout<<prod;
        }

    }
}

Measured memory_bytes: 6372